How to setup Github/Google OAuth?

Question:
Hey everyone! I wanna setup Github OAuth for my program. Having registered my program with the OAuth system, how do I use it now such that a user can click the button and go to the auth page?
Additionally, what does Authorization callback URL mean?
I read the docs and it couldn’t answer any of my questions. Btw, I’m using Flask.

1 Like

If anyone could tell me how to setup Google OAuth, that would be super helpful too. I got redirect_uri_mismatch.

1 Like

When OAuth has authorised your request it then needs to tell your App that it succeeded. It does this via a redirect. That redirect must be URL specified as an “Allowed Callback URL” .

The receiving URL will have an authorization token attached, which you will need to save and add to subsequent requests.

The Authorization callback URL has to exactly match the one you registered with, so don’t get tricky and use a query string.

Keep it simple, to something like “/oauth/github”

What middleware are you using? If you’re not, then consider it. It’ll make life a lot easier.

2 Likes

Erm what does this include?

1 Like

Also, I found that Replit Auth cannot be used if it’s not being run in a repl.
Does anyone know a workaround? Or a simpler Auth method? (Or if someone can help setup Github or Google OAuth in simple terms)

1 Like

@NateDhaliwal The callback url is where the user will be sent back to provide you with the auth data, e.g. https://my.repl.co/loginhttps://accounts.google.com/signin?callback=https://my.repl.co/callback/googlehttps://my.repl.co/callback.google (with the auth token in the request data). All you have to do is to receive the auth data and do stuff with it. Make sure that your callback url is registered in your web server, and that it can receive data.

I remember using Google OAuth in one of my earlier projects, and I would be more than willing to help with further errors.

2 Likes

Do I need to accept this route in my program?

1 Like

Yes, you need to accept it to allow data to get into your webserver.

Isn’t that in the

already?

login is the page where your use goes to be prompted to sign in with google, not the page where you recieve the data.

Oh, because they’re both the same page (/ route handles login, and username data).

hmm interesting, it might work, as long as google uses POST not get (hopefully, i kinda forgot)

Oh, just use Google Firebase Authentication at this point. It’s so much easier.

I was looking at the docs at:

Nothing mentions Python, and at the Firebase docs, it doesn’t mention Python either. The thing is that I need a username from the auth (Github username would be ok), but if I were to use Google, how would I take a username out of the email?
Besides, I need the auth data to be stored in variables in Python. Is there a Python library that is compatible?
Also, what’s the difference between Google auth and Email auth? Won’t they return the email address either way?
Unless, I use the one-tap signup thingy. And, the developer docs provide no code examples.
@boston2029 Is there a way to get the data in Python?

1 Like

Google OAuth is very different than Email Auth:
Here’s Google:

  1. You get a client id & secret
  2. You ask the user to grant your app some permissions (e.g. read their email address)
  3. You find that your user accepted and the google’s auth service has now granted you said permissions
  4. You request the user’s email through google’s API
  5. YAY EMAIL!
  6. Assign auth cookies, etc.

(try pychat.python660.repl.co, and sign in with google, somehow it works.)

Here’s email auth:

  1. You ask user for email + password + confirm password
  2. You store email + password in db, along with an “unverified” flag
  3. You send them a confirmation email
  4. When your user visits the link (with a token of some sort), you verify that token and
  5. You update “unverified” flag to “verified”
  6. YAY EMAIL!
  7. Assign auth cookies, etc
3 Likes

What docs are you looking at!?

1 Like

The… erm… Github README file?

For what? :upside_down_face: You should be looking at Firebase.Google.com docs if you’re trying to add auth

1 Like

I saw that (I think they’re the same) but they require npm and bower installs for JS, but I’m using a Python repl. Of course, I can install them, but I wish to store this data in a Python variable.

What in the world are you talking about? Select Python in the docs…

1 Like