You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.7 KiB
79 lines
2.7 KiB
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using OpenIddict.Client;
|
|
using static OpenIddict.Abstractions.OpenIddictConstants;
|
|
|
|
namespace OpenIddict.Sandbox.AspNetCore.Client;
|
|
|
|
public class Startup
|
|
{
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
})
|
|
|
|
.AddCookie(options =>
|
|
{
|
|
options.LoginPath = "/login";
|
|
options.LogoutPath = "/logout";
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(50);
|
|
options.SlidingExpiration = false;
|
|
});
|
|
|
|
services.AddOpenIddict()
|
|
.AddClient(options =>
|
|
{
|
|
// Add a client registration matching the client application definition in the server project.
|
|
options.AddRegistration(new OpenIddictClientRegistration
|
|
{
|
|
Issuer = new Uri("https://localhost:44395/", UriKind.Absolute),
|
|
|
|
ClientId = "mvc",
|
|
ClientSecret = "901564A5-E7FE-42CB-B10D-61EF6A8F3654",
|
|
RedirectUri = new Uri("https://localhost:44381/signin-oidc", UriKind.Absolute),
|
|
Scopes = { Scopes.Email, Scopes.Profile, Scopes.OfflineAccess, "demo_api" }
|
|
});
|
|
|
|
// Enable the redirection endpoint needed to handle the callback stage.
|
|
options.SetRedirectionEndpointUris("/signin-oidc");
|
|
|
|
// Register the ASP.NET Core host and configure the ASP.NET Core-specific options.
|
|
options.UseAspNetCore()
|
|
.EnableStatusCodePagesIntegration()
|
|
.EnableRedirectionEndpointPassthrough();
|
|
|
|
// Register the signing and encryption credentials used to protect
|
|
// sensitive data like the state tokens produced by OpenIddict.
|
|
options.AddDevelopmentEncryptionCertificate()
|
|
.AddDevelopmentSigningCertificate();
|
|
|
|
// Register the System.Net.Http integration.
|
|
options.UseSystemNetHttp();
|
|
});
|
|
|
|
services.AddHttpClient();
|
|
|
|
services.AddControllersWithViews();
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseStatusCodePagesWithReExecute("/error");
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(options =>
|
|
{
|
|
options.MapControllers();
|
|
options.MapDefaultControllerRoute();
|
|
});
|
|
}
|
|
}
|
|
|