Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Creating a GitHub App

To create your GitHub Oauth application, you’ll need to log in to GitHub then go to https://github.com/settings/applications/new.

00:00 Creating a GitHub Application. To use GitHub authentication with Django user management, you’ll first have to create an application. Log in to your GitHub account and go to the URL seen on-screen and fill in the form.

00:28 The most important part here is the authorization callback URL. It needs to point back to your application. After you’ve registered the application, you’ll be redirected to a page with settings for the application.

00:43 You need to generate a new Client Secret to allow Django social-auth to use GitHub. So click the button, scroll down, and copy the Client Secret to somewhere secure. As GitHub informs you, you won’t be able to see it again. So make sure you don’t skip this step.

01:02 Add the values of Client ID and Client Secret as environment variables.

01:20 Next, add them to settings the same way you added the Mailgun email credentials.

01:44 You can now check if this works. Log out of GitHub and go to your application’s dashboard page. Make sure you’re logged out. The page should say Hello, Guest!.

01:57 And select the option to log in with GitHub. Assuming you’ve logged out after creating the application in that previous step, you should be redirected to GitHub’s login page.

02:12 In the next step, you’ll be asked to authorize the GitHub application. If you confirm, you’ll be redirected back to your application. You can now find a new user in the admin panel.

02:27 The newly created user has the same username as your GitHub handle and doesn’t have a password. In the next section of the course, we’ll take a look at how to fix a problem that’s been created by enabling the GitHub login.

Avatar image for patientwriter

patientwriter on April 23, 2022

What if I already have a social namespace for my users social network? How easy is it to have oauth or whatever use a different namespace?

Avatar image for osiris

osiris on May 8, 2022

Note that callback URL with “localhost” does not work and will result in the following error: “social_core.exceptions.AuthFailed: Authentication failed: The redirect_uri MUST match the registered callback URL for this application.”

Use instead of “localhost”.

Avatar image for Craig

Craig on Feb. 10, 2023

Hi there,

Unfortunately I keep receiving a 404 message on Github, (this is not the page you are looking for).

Steps I have taken to solve this:

  • Making sure I am logged out of Github before I try the process of alternate sign in.

  • I have the oauth set up properly with taking the http from the terminal after running python manage.py runserver, with the additon of oauth/complete/github

  • correct spelling in all parts of the code included in the tutorial.

  • re-exporting the key/secret again

  • followed the tutorial a few times through, starting from scratch each time.

If anyone knows what might be happening/missing from my attempts that would be awesome :)

Avatar image for Craig

Craig on Feb. 10, 2023

Sorry for the above post. I got it to work.

I was not aware that we put in the real credentials when exporting KEY and SECRET into the terminal :)

Become a Member to join the conversation.