Blazor-Auth0-ServerSide 0.3.0-beta-1

Library for Blazor authentication with OIDC Authorization Code-Grant and Implicit-Grant flows, using Auth0's Universal Login and Silent Login

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

Blazor Auth0 Library (server-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-preview5+ server 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-ServerSide.0.3.0-beta-1 to your Blazor Client Side project

Install-Package Blazor-Auth0-ServerSide -Version 0.3.0-beta-1

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

public void ConfigureServices(IServiceCollection services)
{

    //...
	
    services.AddScoped<HttpClient>();

    services.AddScoped((sp) =>
    {
	return new Blazor.Auth0.Shared.Models.ClientSettings()
	{
		Auth0Domain = "[Auth0_Domain]",
		Auth0ClientId = "[Auth0_Client_Id]",
		//// Redirection to home can be forced uncommenting the following line this setting primes over Auth0RedirectUri
		// RedirectAlwaysToHome = true,
		//// Uncomment following line to force the user to be authenticated
		// LoginRequired = true
	};
    });
	
    services.AddScoped<Blazor.Auth0.ServerSide.Authentication.AuthenticationService>();
	
    //...

}

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

  1. Replace the content of App.razor with the following code

@using Blazor.Auth0.Shared.Models.Enumerations
@using Blazor.Auth0.ServerSide.Components
@using Blazor.Auth0.ServerSide.Authentication

@inject AuthenticationService _authService

<CascadingAuthenticationState>

    <AuthComponent ProtectedPaths="protectedPaths">

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

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

            <Router AppAssembly="typeof(Startup).Assembly">

                <NotFoundContent>
                    <p>Sorry, there's nothing at this address.</p>
                </NotFoundContent>

            </Router>

        </AuthorizedContent>

        <UnAuthorizedContent>
            ERROR 401: Unauthorized
        </UnAuthorizedContent>

    </AuthComponent>


</CascadingAuthenticationState>


@code {

    List<string> protectedPaths = new List<string> {
        "fetchdata"
    };

}

Other options include:

  • ProtectedPaths: Allows you to indicate a list of paths that requires an authenticated user, only affects if LoginRequired is set to false.

  • LoginRequiredOnProtectedPaths: Alters the ProtectedPaths behavior. When set to true redirect the user to the login page automatically, otherwise, the content from the UnAuthorizedContent fragment will be rendered.

Blazor Auth0 Library (server-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-preview5+ server 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-ServerSide.0.3.0-beta-1 to your Blazor Client Side project

Install-Package Blazor-Auth0-ServerSide -Version 0.3.0-beta-1

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

public void ConfigureServices(IServiceCollection services)
{

    //...
	
    services.AddScoped<HttpClient>();

    services.AddScoped((sp) =>
    {
	return new Blazor.Auth0.Shared.Models.ClientSettings()
	{
		Auth0Domain = "[Auth0_Domain]",
		Auth0ClientId = "[Auth0_Client_Id]",
		//// Redirection to home can be forced uncommenting the following line this setting primes over Auth0RedirectUri
		// RedirectAlwaysToHome = true,
		//// Uncomment following line to force the user to be authenticated
		// LoginRequired = true
	};
    });
	
    services.AddScoped<Blazor.Auth0.ServerSide.Authentication.AuthenticationService>();
	
    //...

}

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

  1. Replace the content of App.razor with the following code

@using Blazor.Auth0.Shared.Models.Enumerations
@using Blazor.Auth0.ServerSide.Components
@using Blazor.Auth0.ServerSide.Authentication

@inject AuthenticationService _authService

<CascadingAuthenticationState>

    <AuthComponent ProtectedPaths="protectedPaths">

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

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

            <Router AppAssembly="typeof(Startup).Assembly">

                <NotFoundContent>
                    <p>Sorry, there's nothing at this address.</p>
                </NotFoundContent>

            </Router>

        </AuthorizedContent>

        <UnAuthorizedContent>
            ERROR 401: Unauthorized
        </UnAuthorizedContent>

    </AuthComponent>


</CascadingAuthenticationState>


@code {

    List<string> protectedPaths = new List<string> {
        "fetchdata"
    };

}

Other options include:

  • ProtectedPaths: Allows you to indicate a list of paths that requires an authenticated user, only affects if LoginRequired is set to false.

  • LoginRequiredOnProtectedPaths: Alters the ProtectedPaths behavior. When set to true redirect the user to the login page automatically, otherwise, the content from the UnAuthorizedContent fragment will be rendered.

Release Notes

Updated to .NET Core 3.0 Preview 6

Breaking Changes:

AuthComponent ActiveSessionStateContent Removed
AuthComponent InactiveSessionStateContent Removed
AuthComponent ActiveInactiveSessionStateContent Removed

AuthComponent AuthorizedContent Added
AuthComponent UnAuthorizedContent Added
AuthComponent ProtectedPaths Added: Now you can indicate a list of paths, Unauthorized users will either get an 401 error page or redirected to the login page (see ForceLoginOnProtectedPaths)
AuthComponent ForceLoginOnProtectedPaths Added: When set to true will redirect Unauthorized users to the login page

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

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

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

Version History

Version Downloads Last updated
2.0.0-Preview5 304 3/4/2020
2.0.0-Preview4 486 11/17/2019
2.0.0-Preview3 92 11/4/2019
2.0.0-Preview2 83 11/4/2019
2.0.0-Preview1 91 10/26/2019
1.0.0-Preview3 649 9/23/2019
1.0.0-Preview2 121 9/19/2019
1.0.0-Preview1 133 8/24/2019
0.4.2-beta.2 156 7/25/2019
0.4.0-beta.1 174 6/15/2019
0.3.0-beta-1 167 6/14/2019
0.2.1-alpha-2 153 6/12/2019
0.2.0-alpha-1 196 6/5/2019
0.1.0-alpha-2 198 5/8/2019
0.1.0-alpha-1 249 4/20/2019
Show less