Blazor-Auth0-ClientSide 0.3.0-alpha-3

Library for Blazor authentication using Auth0 Authorization Code Grant Flow, Universal Login & Silent Login

This is a prerelease version of Blazor-Auth0-ClientSide.
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package Blazor-Auth0-ClientSide -Version 0.3.0-alpha-3
dotnet add package Blazor-Auth0-ClientSide --version 0.3.0-alpha-3
<PackageReference Include="Blazor-Auth0-ClientSide" Version="0.3.0-alpha-3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazor-Auth0-ClientSide --version 0.3.0-alpha-3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Blazor Auth0 Library (client-side)

This is a library for Blazor authentication with OIDC Authorization Code-Grant and Implicit-Grant flows, using Auth0's Universal Login and Silent Login for Blazor v3.0.0-preview4+ client side solutions, the idea behind this is to have an easy way of using Auth0's services in Blazor without the need of the auth0.js library.

Start using it in 3 simple steps!

  1. Start by adding a reference to Blazor-Auth0-ClientSide.0.3.0-alpha-3 to your Blazor Client Side project

Install-Package Blazor-Auth0-ClientSide -Version 0.3.0-alpha-3

  1. In Startup.cs, register the service inside ConfigureServices method

        public void ConfigureServices(IServiceCollection services)
        {

            services.AddScoped((sp) =>
            {
                return new Blazor.Auth0.ClientSide.Models.ClientSettings()
                {
                    Auth0Domain = "[Auth0_Domain]",
                    Auth0ClientId = "[Auth0_Client_Id]"
                };
            });

            services.AddScoped<Blazor.Auth0.ClientSide.Authentication.AuthenticationService>();
        }

  1. Replace the content of MainLayout.cshtml with the following code

@using Microsoft.AspNetCore.Components.Layouts
@using Blazor.Auth0.ClientSide.Components
@inherits LayoutComponentBase
@inject Blazor.Auth0.ClientSide.Authentication.AuthenticationService _authService

<AuthComponent>

    @*Will render while determining user's session state*@
    <UndefinedSessionStateContent>
        Determining session state, please wait...
    </UndefinedSessionStateContent>

    @*Will render after determining session state*@
    <ActiveInactiveSessionStateContent>

        <div class="sidebar">
            <NavMenu />
        </div>

        <div class="main">
            <div class="top-row px-4">
                @if (_authService.SessionState == Blazor.Auth0.ClientSide.Models.Enumerations.SessionStates.Active)
                {
                    <a href="" class="ml-md-auto" onclick="@_authService.LogOut">LogOut</a>
                }
                else
                {
                    <a href="" class="ml-md-auto" onclick="@_authService.Authorize">LogIn</a>
                }
            </div>
            <div class="content px-4">
                @Body
            </div>
        </div>

    </ActiveInactiveSessionStateContent>

    @*There's also options for showing content on Active & Inactive session states alone*@
    <ActiveSessionStateContent></ActiveSessionStateContent>
    <InactiveSessionStateContent></InactiveSessionStateContent>

</AuthComponent>

Other options include:

  • AuthenticationGrant: Allows you to choose between authorization_code (recommended) and implicit_grant authentication flows.

  • RedirectAlwaysToHome: When set to true, forces the redirect_uri param to be the home path, this value overrides Auth0RedirectUri

  • LoginRequired: When set to true, forces a redirection to the login page in case the user is not authenticated.

  • GetUserInfoFromIdToken: When set to true, the serivce will use the id_token payload to build the user info, this is good in case all the user info you require is present in the id_token payload and you want avoid doing an extra call to Auth0, in case that tere's no id_token present in the authentication response the service will fall back gracefully to try to get the user info from an API call to auth0, default value is false

Known issues

  • No server-side support yet

Blazor Auth0 Library (client-side)

This is a library for Blazor authentication with OIDC Authorization Code-Grant and Implicit-Grant flows, using Auth0's Universal Login and Silent Login for Blazor v3.0.0-preview4+ client side solutions, the idea behind this is to have an easy way of using Auth0's services in Blazor without the need of the auth0.js library.

Start using it in 3 simple steps!

  1. Start by adding a reference to Blazor-Auth0-ClientSide.0.3.0-alpha-3 to your Blazor Client Side project

Install-Package Blazor-Auth0-ClientSide -Version 0.3.0-alpha-3

  1. In Startup.cs, register the service inside ConfigureServices method

        public void ConfigureServices(IServiceCollection services)
        {

            services.AddScoped((sp) =>
            {
                return new Blazor.Auth0.ClientSide.Models.ClientSettings()
                {
                    Auth0Domain = "[Auth0_Domain]",
                    Auth0ClientId = "[Auth0_Client_Id]"
                };
            });

            services.AddScoped<Blazor.Auth0.ClientSide.Authentication.AuthenticationService>();
        }

  1. Replace the content of MainLayout.cshtml with the following code

@using Microsoft.AspNetCore.Components.Layouts
@using Blazor.Auth0.ClientSide.Components
@inherits LayoutComponentBase
@inject Blazor.Auth0.ClientSide.Authentication.AuthenticationService _authService

<AuthComponent>

    @*Will render while determining user's session state*@
    <UndefinedSessionStateContent>
        Determining session state, please wait...
    </UndefinedSessionStateContent>

    @*Will render after determining session state*@
    <ActiveInactiveSessionStateContent>

        <div class="sidebar">
            <NavMenu />
        </div>

        <div class="main">
            <div class="top-row px-4">
                @if (_authService.SessionState == Blazor.Auth0.ClientSide.Models.Enumerations.SessionStates.Active)
                {
                    <a href="" class="ml-md-auto" onclick="@_authService.LogOut">LogOut</a>
                }
                else
                {
                    <a href="" class="ml-md-auto" onclick="@_authService.Authorize">LogIn</a>
                }
            </div>
            <div class="content px-4">
                @Body
            </div>
        </div>

    </ActiveInactiveSessionStateContent>

    @*There's also options for showing content on Active & Inactive session states alone*@
    <ActiveSessionStateContent></ActiveSessionStateContent>
    <InactiveSessionStateContent></InactiveSessionStateContent>

</AuthComponent>

Other options include:

  • AuthenticationGrant: Allows you to choose between authorization_code (recommended) and implicit_grant authentication flows.

  • RedirectAlwaysToHome: When set to true, forces the redirect_uri param to be the home path, this value overrides Auth0RedirectUri

  • LoginRequired: When set to true, forces a redirection to the login page in case the user is not authenticated.

  • GetUserInfoFromIdToken: When set to true, the serivce will use the id_token payload to build the user info, this is good in case all the user info you require is present in the id_token payload and you want avoid doing an extra call to Auth0, in case that tere's no id_token present in the authentication response the service will fall back gracefully to try to get the user info from an API call to auth0, default value is false

Known issues

  • No server-side support yet

Release Notes

- Upgraded to latest Blazor 3.0.0-preview4-19216-03

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Blazor-Auth0-ClientSide:

Package Downloads
Blazor-OpenId
OpenId library for Balzor

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Blazor-Auth0-ClientSide:

Repository Stars
henalbrod/Blazor.Auth0
The library for using Auth0 in Blazor applications.

Version History

Version Downloads Last updated
2.0.0-Preview5 834 3/4/2020
2.0.0-Preview4 556 11/17/2019
2.0.0-Preview3 106 11/4/2019
2.0.0-Preview2 99 11/4/2019
2.0.0-Preview1 90 10/26/2019
1.0.0-Preview3 690 9/23/2019
1.0.0-Preview2 105 9/19/2019
1.0.0-Preview1 141 8/24/2019
0.7.2-beta.2 154 7/25/2019
0.7.0-beta.1 153 6/15/2019
0.6.0-beta-1 121 6/14/2019
0.5.1-alpha-2 154 6/12/2019
0.5.0-alpha-1 192 6/5/2019
0.4.0-alpha-2 217 5/8/2019
0.4.0-alpha-1 271 4/20/2019
0.3.0-alpha-3 199 4/20/2019
Show less