Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Google OAuth 2.0 Authentication in Blazor with AutoRenderMode Support #23

Merged
merged 13 commits into from
Dec 20, 2024

Conversation

neozhu
Copy link
Owner

@neozhu neozhu commented Dec 20, 2024

Untitled.video.-.Made.with.Clipchamp.7.mp4

Description

This PR introduces Google OAuth 2.0 Authentication to support external login in Blazor applications, including the ability to register and sign in users via Google.

Key Features:

  1. Google Application Registration:

    • Added configuration to support Google OAuth:
      "Authentication": {
        "Google": {
          "ClientId": "your-client-id",
          "ClientSecret": "your-client-secret"
        }
      }
    • Replace "your-client-id" and "your-client-secret" with values from your Google Developer Console.
  2. Generate Google Login URL:

    • Added a route /google/loginUrl to dynamically generate the Google OAuth 2.0 authorization URL.
    • Example Usage:
      GET /google/loginUrl?state=your-redirect-uri
      • Returns a URL that clients can use to initiate the Google login flow.
  3. Handle Google Sign-In Callback:

    • Added a route /google/signIn to exchange the Google authorization code for an ID token.
    • Validates the token, creates a user if necessary, and signs in the user.
    • Behavior:
      • Existing users are logged in.
      • New users are automatically registered with the following properties:
        • Email
        • Name (Google profile name)
        • Avatar URL
        • Default settings like LanguageCode and TimeZoneId.

Routes:

  • GET /google/loginUrl: Generates the Google OAuth 2.0 login URL.
  • POST /google/signIn: Handles the authorization code exchange and signs in the user.

@neozhu neozhu merged commit ac5de14 into main Dec 20, 2024
5 checks passed
@neozhu neozhu deleted the feature/googleauthorization branch December 20, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant