Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

jbomhold3/Blazor.Openid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blazor.OpenId

This is a library for Blazor authentication with OpenId Authorization Code-Grantflow, using IdenityServer or other OpenId providers and Silent Refresh for Blazor over .NET Core v3.0.0 client & server-side solutions, the idea behind this is to have an easy way of using OpenId services in Blazor without the need of the js library.

Nuget

Prerequisites

Blazor

You'll want to follow the Getting Started instructions in Blazor website

IdenityServer or Another OpenId Server

You need need to setup and configure OpenId Server. By default Blazor.OpenId redirects to the root of your application.

Installation

Install via Nuget.

Server Side

Install-Package Blazor-OpenId  

Usage

Note: Following example is for a server-side with require authenticated user implementation, for client-side and core-hosted example implementations please refer to the examples

Startup.cs

// Import Blazor.Auth0
using Blazor.Auth0;
using Blazor.Auth0.Models;
// ...

public void ConfigureServices(IServiceCollection services)
{
	// Other code...

	/// This one-liner will initialize Blazor.Auth0 with all the defaults
	    services.AddBlazorOpenid(options =>
            {
                options.Domain = "[Your-Domain]";
                options.ClientId = "[Your-Client-Id]";
                options.SlidingExpiration = true;
                options.Scope = "[Your-Scopes]";  // By default openid profile email
                options.RequestMode = Blazor.OpenId.Models.RequestModes.Form_Post;
            });

	// Other code...
}

Replace App.razor content with the following code

App.razor

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <Authorizing>
                <p>>Determining session state, please wait...</p>
            </Authorizing>
            <NotAuthorized>
                <h1>Sorry</h1>
                <p>You're not authorized to reach this page. You may need to log in as a different user.</p>
            </NotAuthorized>
        </AuthorizeRouteView>
    </Found>
    <NotFound>        
        <p>Sorry, there's nothing at this address.</p>        
    </NotFound>
</Router>

Authors

John J Bomhold - OpenId implementation of Auth0

Blazor.Auth0 was created by Henry Alberto Rodriguez - GitHub - Twitter - Linkedin

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published