Sparc.Blossom.Authentication.AzureADB2C 7.1.0-pre.2

This is a prerelease version of Sparc.Blossom.Authentication.AzureADB2C.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Sparc.Blossom.Authentication.AzureADB2C --version 7.1.0-pre.2                
NuGet\Install-Package Sparc.Blossom.Authentication.AzureADB2C -Version 7.1.0-pre.2                
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="Sparc.Blossom.Authentication.AzureADB2C" Version="7.1.0-pre.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sparc.Blossom.Authentication.AzureADB2C --version 7.1.0-pre.2                
#r "nuget: Sparc.Blossom.Authentication.AzureADB2C, 7.1.0-pre.2"                
#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 Sparc.Blossom.Authentication.AzureADB2C as a Cake Addin
#addin nuget:?package=Sparc.Blossom.Authentication.AzureADB2C&version=7.1.0-pre.2&prerelease

// Install Sparc.Blossom.Authentication.AzureADB2C as a Cake Tool
#tool nuget:?package=Sparc.Blossom.Authentication.AzureADB2C&version=7.1.0-pre.2&prerelease                

Sparc.Authentication.AzureADB2C

Nuget

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:

  1. Add the Sparc.Authentication.AzureADB2C Nuget package: Nuget

  2. 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"
       }
     }
    
  3. Add the following line of code to your Program.cs file to register the Sparc.Authentication.AzureADB2C plugin. It will automatically read the data from the AzureAdB2C configuration in your appsettings.json.

    builder.Services.AddAzureADB2CAuthentication(builder.Configuration);
    

In your Platform projects (Web/Maui):

  1. 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
      }
    }
    
  2. 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 or MauiProgram.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)

  1. (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>
    
  2. 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.

  3. To log in, set your login button to navigate to /authentication/login?returnUrl=. To log out, navigate to /authentication/logout.

Product 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. 
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
7.1.0 173 5/10/2023
7.1.0-pre.2 159 12/13/2022