public static IServiceCollection AddPingOneManagement( this IServiceCollection services, PingOneConfigurationManagement configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } PingOneConfigurationValidator.ValidateManagementConfiguration(configuration); services.AddSingleton(configuration); services.AddSingleton <IMemoryCache, MemoryCache>(); services.AddHttpClient <IPingOneTokenProvider, PingOneTokenProvider>( nameof(IPingOneTokenProvider), client => { client.BaseAddress = new Uri($"{configuration.AuthBaseUrl}/{configuration.EnvironmentId}/as/"); }); services.AddHttpClient <IManagementApiClient, ManagementApiClient>( nameof(IManagementApiClient), client => { client.BaseAddress = new Uri($"{configuration.ApiBaseUrl}/v1/environments/{configuration.EnvironmentId}/"); }) .AddHttpMessageHandler <PingOneApiAuthorizationHeaderHandler>(); services.AddTransient <PingOneApiAuthorizationHeaderHandler>(); return(services); }
public static IServiceCollection AddPingOneAuthentication( this IServiceCollection services, string authenticationScheme, PingOneConfigurationAuthentication configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } PingOneConfigurationValidator.ValidateAuthenticationConfiguration(configuration); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie() .AddOpenIdConnect(authenticationScheme, options => { options.ClaimsIssuer = authenticationScheme; options.Authority = $"{configuration.AuthBaseUrl}/{configuration.EnvironmentId}/as"; options.ClientId = configuration.ClientId; options.ClientSecret = configuration.Secret; options.CallbackPath = new PathString(configuration.RedirectPath); options.SaveTokens = true; options.ResponseType = configuration.ResponseType; options.Scope.Clear(); foreach (var scope in configuration.Scopes) { options.Scope.Add(scope); } options.Events = new OpenIdConnectEvents { OnRedirectToIdentityProviderForSignOut = context => { context.ProtocolMessage.PostLogoutRedirectUri = configuration.PostSignOffRedirectUrl; return(Task.FromResult(0)); }, }; }); return(services); }