Implement login with google in python flask applications with authlib
Вставка
- Опубліковано 4 лип 2024
- Blog post - nagasudhir.blogspot.com/2023/...
OAuth 2.0 Authorization Code flow explained - • OAuth 2.0 Authorizatio...
Introduction to OAuth 2.0 - • Introduction to OAuth 2.0
Setup Keycloak as OAuth 2.0 server in Windows for development and testing - • Setup Keycloak as OAut...
Client credentials flow and JWT explained - • OAuth 2.0 client crede...
In this video, we will learn we will learn how to implement login with google in flask applications.
Also we will fetch user’s personal information like age and gender from google after the user logs in
Table of contents - nagasudhir.blogspot.com/2020/...
Please subscribe, like and share this video
00:00 - Intro
01:55 - OAuth 2.0 Authorization Code flow
03:32 - Authlib python module
04:19 - Register application in Google Cloud Console
10:53 - Creating flask application with google login
14:24 - login redirection endpoint in flask application
15:46 - login callback endpoint in flask application
16:38 - logging in the user with flask session
17:26 - Render user information in home page
20:58 - Access token to fetch gender and age from google people API
24:02 - User Logout implementation
24:52 - Render gender and birthday data
25:41 - Summary of flask application
26:05 - Outro
#google #oauth #authlib #sso #server #setup #python #web #dev #tutorial #learning #beginners #taming_python - Наука та технологія
cool video keep the good work !!!
Thank you 👍
thank you.
You are welcome 👍
hello, amazing tutorial! I got this working with flask but I also have a frontend with React and I was wondering if you could help me out. When a perform an axios request to localhost:3000/google_login it keeps giving me a 302 error. I tried changing the url to localhost:5000/google_login but it still doesn't work. Also, my endpoint is google_login not google-login which redirect to an endpoint google_callback.
Hi, this works for OAuth 2.0 Authorization code flow. For Single Page Applications like react applications, this flow cannot be used directly.
great video, but i think the oauth2 login should be handled by FE side more than BE side (Flask)
Hi, the workflow demonstrated in this video is for server side applications. The authorisation at Front end will be relevant in single page apps (SPA). I think that is also supported by Google
Cheers👍
will this work for a flask app that has several instances running a basic round robin load balance? so basically can the session and users data be used between separate servers ?
Hi, when the user logs in, a session will be created in the server. The session storage is generally the RAM of the server. So this would not work with load balancing.
For a load balanced servers scenario, the session storage should be centralised in redis or any fast database.
stackoverflow.com/a/48318231/2746323
Hope this helps, cheers👍
Thank you very much!
Nice question. Nice Answer.
hey i am getting this type of message - "message": "Error Missing \"authorize_url\" value"
Hi, the source code for this video can be found in the blog at nagasudhir.blogspot.com/2023/05/implement-login-with-google-in-python.html
Please check if the code is ok for the Google callback function and the configuration.
Also please check the Google oauth client settings as shown in the video.
If still the error is coming, please share your source code so that we can debug the issue.
Hope this helps cheers 👍
after logout I want to login with different email. What to do for that?
Hi, if you want to login with another Gmail. It is really simple. Just logout and login again. The sample code shown in the video and blogpost. Hope this helps, cheers 👍
@@learningsoftwareskills no it's not working. I tried explaining in comment but for some it is getting deleted again and again
@@rishabhsingh6307 hi can you mail your code to learningsoftwareskills@gmail.com
I want to login with another email but it doesn't work
Hi, your email provider should support OAuth 2.0 Authorization code flow to support sign in with email. Please verify the same
what about refresh tokens?
Hi, this example is for interactive applications in a server side web application. Hence, the session is managed by the flask application. The oauth server will be again contacted only when the session is expired in the flask server. So in most of the cases, refresh token is not required in server side web applications.
Hope this helps, cheers 👍
@@learningsoftwareskills ohhh ok, i'm doing a login flow from the authorization server and from the client application perspective, so i had several questions about how to implement that
i keep getting a OAuth.register("myApp",
TypeError: OAuth.register() missing 1 required positional argument: 'name'
Hi, you should write "oauth.register" instead of "Oauth.register" . Because OAuth is the class and oauth is the object.
Hope this helps, cheers👍