Sparc.Blossom.Authentication.AzureADB2C
7.1.0
dotnet add package Sparc.Blossom.Authentication.AzureADB2C --version 7.1.0
NuGet\Install-Package Sparc.Blossom.Authentication.AzureADB2C -Version 7.1.0
<PackageReference Include="Sparc.Blossom.Authentication.AzureADB2C" Version="7.1.0" />
paket add Sparc.Blossom.Authentication.AzureADB2C --version 7.1.0
#r "nuget: Sparc.Blossom.Authentication.AzureADB2C, 7.1.0"
// Install Sparc.Blossom.Authentication.AzureADB2C as a Cake Addin #addin nuget:?package=Sparc.Blossom.Authentication.AzureADB2C&version=7.1.0 // Install Sparc.Blossom.Authentication.AzureADB2C as a Cake Tool #tool nuget:?package=Sparc.Blossom.Authentication.AzureADB2C&version=7.1.0
Sparc.Authentication.AzureADB2C
The Sparc.Authentication.AzureADB2C
plugin is a plug-and-play authentication plugin that hooks up all API authentication in your Features Project to Azure AD B2C.
Add this plugin to your Features Project if you'd like to use Azure AD B2C as your app's authentication provider.
Get Started with Sparc.Authentication.AzureADB2C
Set up Azure Active Directory B2C
Follow the guide here to set up two applications within Azure AD B2C -- one for your Features Project, and one for your UI Project.
Take note of the following items as you are setting things up. You will need these later on in the process:
- The name of your B2C domain
- The Client ID (Guid) of your Azure AD B2C Features (Server) Application
- The Client ID (Guid) of your Azure AD B2C UI (Client) Application
- The Sign Up/Sign In and Reset Password Policy IDs
- The URI of the scope you create to connect the Features (Server) & UI (Client) applications
In Your Features Project:
Add the following settings to your
appsettings.json
file, replacing the values as necessary to match your application:{ "AzureAdB2C": { "Instance": "https://mydomainname.b2clogin.com/tfp/", "ClientId": "00000000-0000-0000-0000-000000000000", // the Client ID of your Azure AD B2C Features/API Project "Domain": "mydomainname.onmicrosoft.com", "SignUpSignInPolicyId": "B2C_1_SignIn_SignUp", "ResetPasswordPolicyId": "B2C_1_ForgotPassword" } }
Add the following line of code to your
Program.cs
file to register theSparc.Authentication.AzureADB2C
plugin. It will automatically read the data from theAzureAdB2C
configuration in yourappsettings.json
.builder.Services.AddAzureADB2CAuthentication(builder.Configuration);
In your Platform projects (Web/Maui):
Add the following settings to your
wwwroot/appsettings.json
file, replacing the values as necessary to match your application:{ "AzureAdB2C": { "Authority": "https://mydomainname.b2clogin.com/tfp/mydomainname.onmicrosoft.com/B2C_1_SignIn_SignUp", "ClientId": "00000000-0000-0000-0000-000000000000", // the Client ID of your Azure AD B2C UI Project "ValidateAuthority": false } }
You just need to add Blossom to your platform project to register the client features in Authentication, add the following line of code to your
Program.cs
orMauiProgram.cs
file.builder.AddBlossom<MyAppApi>(builder.Configuration["ApiUrl"]);
pass in your auto-generated Api class type (generated from your OpenApiReference -- more info in the Sparc.Blossom documentation)
(Web projects only) Add the following line of code to your
index.html
file. This adds the necessary JS library for Blazor Web Assembly Authentication using MSAL:<script src="_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js"></script>
Run your solution. All of your Features will be automatically protected with JWT-based access tokens, and these access tokens will be sent automatically when the users are logged in.
To log in, set your login button to navigate to
/authentication/login?returnUrl=
. To log out, navigate to/authentication/logout
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Identity.Web (>= 1.25.10)
- Sparc.Blossom.Core (>= 7.1.0)
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 |
---|---|---|
7.1.0 | 173 | 5/10/2023 |
7.1.0-pre.2 | 159 | 12/13/2022 |