55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using OpenIddict.Validation.AspNetCore;
|
|
|
|
namespace Fengling.AuthService.Configuration;
|
|
|
|
public static class OpenIddictSetup
|
|
{
|
|
public static IServiceCollection AddOpenIddictConfiguration(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration
|
|
)
|
|
{
|
|
services
|
|
.AddOpenIddict()
|
|
.AddCore(options =>
|
|
{
|
|
options.UseEntityFrameworkCore().UseDbContext<Data.ApplicationDbContext>();
|
|
})
|
|
.AddServer(options =>
|
|
{
|
|
options.SetIssuer(
|
|
configuration["OpenIddict:Issuer"] ?? "https://auth.fengling.local"
|
|
);
|
|
|
|
options.AddDevelopmentEncryptionCertificate().AddDevelopmentSigningCertificate();
|
|
|
|
options
|
|
.AllowAuthorizationCodeFlow()
|
|
.AllowPasswordFlow()
|
|
.AllowRefreshTokenFlow()
|
|
.RequireProofKeyForCodeExchange();
|
|
|
|
options.RegisterScopes("api", "offline_access");
|
|
|
|
options.UseAspNetCore();
|
|
})
|
|
.AddValidation(options =>
|
|
{
|
|
options.UseLocalServer();
|
|
options.UseAspNetCore();
|
|
});
|
|
|
|
services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultAuthenticateScheme =
|
|
OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
|
|
options.DefaultChallengeScheme =
|
|
OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|