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
  • Наука та технологія

КОМЕНТАРІ • 25

  • @theluvit
    @theluvit Рік тому +1

    cool video keep the good work !!!

  • @yashdharmale4836
    @yashdharmale4836 Рік тому +1

    thank you.

  • @dgaming-hg7dl
    @dgaming-hg7dl 7 місяців тому +1

    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.

    • @learningsoftwareskills
      @learningsoftwareskills  5 місяців тому

      Hi, this works for OAuth 2.0 Authorization code flow. For Single Page Applications like react applications, this flow cannot be used directly.

  • @futhedude4848
    @futhedude4848 8 місяців тому +1

    great video, but i think the oauth2 login should be handled by FE side more than BE side (Flask)

    • @learningsoftwareskills
      @learningsoftwareskills  8 місяців тому +1

      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👍

  • @user-ho7qy4tx6v
    @user-ho7qy4tx6v 5 місяців тому +2

    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 ?

    • @learningsoftwareskills
      @learningsoftwareskills  5 місяців тому +2

      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👍

    • @user-ho7qy4tx6v
      @user-ho7qy4tx6v 5 місяців тому +1

      Thank you very much!

    • @namahshrestha3226
      @namahshrestha3226 4 місяці тому +1

      Nice question. Nice Answer.

  • @user-bc2hi5zy5c
    @user-bc2hi5zy5c 7 місяців тому +1

    hey i am getting this type of message - "message": "Error Missing \"authorize_url\" value"

    • @learningsoftwareskills
      @learningsoftwareskills  7 місяців тому +2

      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 👍

  • @rishabhsingh6307
    @rishabhsingh6307 10 місяців тому +1

    after logout I want to login with different email. What to do for that?

    • @learningsoftwareskills
      @learningsoftwareskills  10 місяців тому +1

      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 👍

    • @rishabhsingh6307
      @rishabhsingh6307 10 місяців тому

      @@learningsoftwareskills no it's not working. I tried explaining in comment but for some it is getting deleted again and again

    • @learningsoftwareskills
      @learningsoftwareskills  10 місяців тому

      @@rishabhsingh6307 hi can you mail your code to learningsoftwareskills@gmail.com

  • @rotimipraise9351
    @rotimipraise9351 5 місяців тому +1

    I want to login with another email but it doesn't work

    • @learningsoftwareskills
      @learningsoftwareskills  5 місяців тому

      Hi, your email provider should support OAuth 2.0 Authorization code flow to support sign in with email. Please verify the same

  • @nimouh9816
    @nimouh9816 Місяць тому

    what about refresh tokens?

    • @learningsoftwareskills
      @learningsoftwareskills  Місяць тому

      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 👍

    • @nimouh9816
      @nimouh9816 Місяць тому +1

      @@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

  • @user-mk8zy1wy5d
    @user-mk8zy1wy5d 9 місяців тому +1

    i keep getting a OAuth.register("myApp",
    TypeError: OAuth.register() missing 1 required positional argument: 'name'

    • @learningsoftwareskills
      @learningsoftwareskills  9 місяців тому

      Hi, you should write "oauth.register" instead of "Oauth.register" . Because OAuth is the class and oauth is the object.
      Hope this helps, cheers👍