# Social Auth notes ## basic python_social_auth ### How to Add Social Login to Django [How to Add Social Login to Django](https://simpleisbetterthancomplex.com/tutorial/2016/10/24/how-to-add-social-login-to-django.html) #### pre test notes 1. disable 'test_social.middleware.ForwardHQMiddleware' 2. reset LOGIN_REDIRECT_URL = '/tsoc' or to wherever you want it to land 3. set SOCIAL_AUTH_URL_NAMESPACE = 'social' 4. DON'T use localhost if you plan on using twitter, twitter doesn't like it #### error in login [stackoverflow desc](https://stackoverflow.com/questions/46975657/attributeerror-module-django-contrib-auth-views-has-no-attribute-login) change: `path('login/', views.login, name='login')` `path('login/', views.LoginView.as_view(template_name="registration/login.django"), name='login')` #### when making callback urls - you can use localhost - you can also specify a port on localhost, e.g. http://localhost:8026 - you can also use minyanfinder.stg or any .stg - make sure to specify the "u" letter in oauth - make sure to add the final forward slash "/" at the end of the callback url `minyanfinder.stg/oauth/complete/twitter/` ## global variables global variables should be in settings.py local info like the specific client id/secret key, etc, should be in the local setting sfiles test_social should only be activated in the local setting files ### twitter notes 1. you want to either use http or https, be specific 2. twitter does not use localhost and forwardhq is buggy 3. twitter DOES register 127.0.0.1:8026 as a callback ### facebook notes 1. can use localhost 2. minaynfinder.stg is not working, need a certificate of some kind 3. forwardhq also not working #### using a domain ##### create registered users Go to Roles->Test Users ##### create the ssl 1. set a registered domain name to point at the ip address (ie ronnyabraham.com) 2. create a [https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs#generating-ssl-certificates](crt certificate) 3. `Settings->Basic-> App Domains` add `ronnyabraham.com` 4. `Settings->Basic->Website/Site URL` add `https://ronnyabraham.com` 5. in Products->FacebookLogin->Settings add the following to "VAlid OAuth Redirect URIs" - https://ronnyabraham.com - https://ronnyabraham.com/oauth/complete/facebook/ 6. use letsencrypt to create ssl keys ### setting up facebook 1. if used for testing make sure you set the app FOR TESTING you have to do this in the create app stage 2. [select create test app from the app you like](https://imgur.com/RzK3pS3) 3. go to settings->basic get the app-id and app-secret 4. go to Settings-Basic-App Domains and add your FQDN (ie. mycrustyass.com) 5. go to Settings-Basic-Website (it's near the bottom, add website if it isn't there), add the site URL with it's prefix ie http or https. Step 5 is VERY IMPORTANT b/c facebook doesn't recognize http prefix. You must have SSL set up. But this is NOT the caes with localhost! 6. in Settings-Products add Facebook Login then set Web OAuth Login to true 7. Settings-Products-Facebook Login add Valid OAuth redirect calls. Important! You must find out what the specific redirect call looks like. Once again, facebook doesn't require this for localhost, but for a named host it does e.g. https://mycrustyass.com/oauth/complete/facebook/ 8. test this URL in the Settings-Products-FAcebook Login-Redirect URL Validator