Shaddix.OpenIddict.ExternalAuthentication 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Shaddix.OpenIddict.ExternalAuthentication --version 1.0.5                
NuGet\Install-Package Shaddix.OpenIddict.ExternalAuthentication -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shaddix.OpenIddict.ExternalAuthentication" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shaddix.OpenIddict.ExternalAuthentication --version 1.0.5                
#r "nuget: Shaddix.OpenIddict.ExternalAuthentication, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Shaddix.OpenIddict.ExternalAuthentication as a Cake Addin
#addin nuget:?package=Shaddix.OpenIddict.ExternalAuthentication&version=1.0.5

// Install Shaddix.OpenIddict.ExternalAuthentication as a Cake Tool
#tool nuget:?package=Shaddix.OpenIddict.ExternalAuthentication&version=1.0.5                

OpenIddictExternalAuthentication

NUGET MIT NET6

OpenIddict extension that allows adding Login with Facebook or Login with Google buttons into your React/Angular/PlainJS/whatever SPA (implying you are using OpenIddict on backend). Based on OpenIddict Samples, and could be treated as another sample with JS client and external authentication providers. Implementation is based on Kevin Chalet answers on SPA social login issue.

Here's the vanilla js or react demo if you care. The page has several buttons to log in via different providers. Example workflow

How to

  1. PREREQUISITE: it's implied, that openiddict is installed and configured in your project already (if it's not, head over to one of the samples).

  2. Install nuget to add the library to your project.

     dotnet add package Shaddix.OpenIddict.ExternalAuthentication
    
  3. Create you own AuthorizationController by inheriting from OpenIdAuthorizationControllerBase. This could look like:

    public class AuthorizationController : OpenIdAuthorizationControllerBase<IdentityUser, string>
    {
        public AuthorizationController(SignInManager<IdentityUser> signInManager,
         UserManager<IdentityUser> userManager,
         IOpenIddictClientConfigurationProvider clientConfigurationProvider) : base(signInManager, userManager,
         clientConfigurationProvider)
         {
         }
    
    }
    
  4. Override some functions (e.g. CreateNewUser or GetClaims) if you want to customize user creation behavior or provide more claims.

  5. From Configure function in Startup.cs add the following calls (in addition to standard OpenIddict setup):

    services
       .AddOpenIddict()
       .AddOpenIddictConfigurations(Configuration)
       .AddDefaultAuthorizationController()
    
  6. Add external auth providers (i.e. .AddAuthentication().AddGoogle(), .AddFacebook(), etc.). Follow instructions on how to set up applications on OAuth provider side.

You could also take a look at OpenIddictExternalAuthentication.Example for example usage (keep in mind, that there are hardcoded ClientId/ClientSecret for FB and Google within Example app. They are for demo purposes and everyone can use them, so beware).

Frontend

  1. Use some proven openid client library (I personally recommend oidc-client-ts).
  2. Use standard auth code flow according to the library instructions, pointing to standard Authorize endpoint and passing ?provider=Google as a query parameter (i.e. authorization endpoint should look like /connect/authorize?provider=Google).
  3. You could check example implementation in plain-js or React

External user storage

We use standard Asp.Net Identity mechanism to store external logins (namely, AspNetUserLogins table). To find a user by external OAuth id you need to use _userManager.FindByLoginAsync(providerName, externalUserId)

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.7.1 108 11/8/2024
2.6.9 1,842 3/6/2024
2.6.8 7,715 12/24/2023
2.6.7 120 12/24/2023
2.6.6 4,393 5/2/2023
2.6.5 161 5/2/2023
2.6.4 344 5/2/2023
2.6.3 146 5/2/2023
2.6.2 149 5/2/2023
2.6.1 142 5/2/2023
2.5.1 165 5/1/2023
2.4.3 8,932 12/23/2022
2.4.2 2,545 12/17/2022
2.4.1 284 12/17/2022
2.3.2 1,766 10/24/2022
2.3.1 2,233 8/15/2022
2.2.2 2,235 7/23/2022
2.2.1 525 7/20/2022
2.1.3 797 7/8/2022
2.1.2 427 7/7/2022
2.1.1 447 7/6/2022
2.0.3 1,047 6/21/2022
2.0.2 475 6/20/2022
2.0.1 395 6/20/2022
1.4.5 463 6/20/2022
1.4.4 396 6/20/2022
1.4.3 427 6/20/2022
1.4.2 418 6/19/2022
1.4.1 422 6/19/2022
1.3.2 431 6/18/2022
1.3.1 434 6/17/2022
1.2.3 487 6/9/2022
1.2.2 398 6/9/2022
1.2.1 425 6/8/2022
1.1.4 427 5/29/2022
1.1.3 984 5/5/2022
1.1.2 1,203 3/14/2022
1.0.5 438 3/14/2022
1.0.4 450 3/13/2022
1.0.2 431 3/13/2022
1.0.1 415 3/13/2022