Replies: 1 comment 5 replies
-
This is your frontend that will make the API calls to the OAuth routes. 1. AuthorizationThe first thing is to generate the right authorization URL for the OAuth Provider (here, Google). From your frontend, you call the {
"authorization_url": "https://www.tintagel.bt/oauth/authorize?client_id=CLIENT_ID&scopes=a+b&redirect_uri=https://www.camelot.bt/oauth/callback"
} You should redirect your user to window.location.href = authorization_url 2. CallbackAfter user has authenticated on Google, they'll be redirected to your application. That's the "callback". What I usually suggest is to make a redirection to a special page on your frontend. The URL will look like this:
At that moment, from your JS app, you can catch the flowchart LR
subgraph BACKEND [Backend]
AUTH["/oauth/authorize"]
CB["/oauth/callback"]
end
subgraph FRONTEND [Frontend]
FAUTH["/authorize"]
FCB["/oauth-callback"]
end
GOOGLE[Google]
FAUTH -- asks URL --> AUTH
AUTH -- returns URL --> FAUTH
FAUTH -- redirects to URL --> GOOGLE
GOOGLE -- redirects --> FCB
FCB -- forwards code --> CB
CB -- returns token --> FCB
3. CORSYou may have CORS errors from your browsers if your frontend is not on the same domain as your backend. That's a normal security measure from your browser. If you need to relax that security measure, you have to setup a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We use fastapi-users to integrate Google auth. By default there are defined to endpoints
/auth/google/authorize
and/auth/google/callback
.So frontend which is in Angular calls
/auth/google/authorize
and as result we got URL in body. Than if we call this URL we got CORS error. After that we are not sure if this is right approach or on which order should we call API.Also API
/auth/google/callback
has code, code_verifier, state and error fields where we get this fields?We use fastapi-users package in our backend. We have major problems with integrating Google OAuth.
URL: google auth
By default there are two endpoints
/auth/google/authorize
and/auth/google/callback
.What is actually a flow for these endpoints? When we call the /auth/google/authorize endpoint, the response is:
We tried then calling this URL again in the frontend, because if we copy paste this URL in google, the response is token and token type.
If we call this endpoint in our frontend, we get CORS error.
Is this even right approach? What frontend should do with these two endpoints? And what to do with the /auth/google/callback endpoint?
Thanks to everyone for help
@frankie567 Please could you help. Thank you
Beta Was this translation helpful? Give feedback.
All reactions