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.
You'll want to follow the Getting Started instructions in Blazor website
You need need to setup and configure OpenId Server. By default Blazor.OpenId redirects to the root of your application.
Install via Nuget.
Server Side
Install-Package Blazor-OpenId
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
// 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
<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>
John J Bomhold - OpenId implementation of Auth0
Blazor.Auth0 was created by Henry Alberto Rodriguez - GitHub - Twitter - Linkedin
This project is licensed under the MIT License - see the LICENSE file for details.