Esempio n. 1
0
        public static IServiceCollection AddProfileTokenProvider(this IServiceCollection services, AuthenticationProviderType authenticationProviderType, string profile = "ivan")
        {
            switch (authenticationProviderType)
            {
            case AuthenticationProviderType.Local:
                services.AddTransient <IProfileTokenProvider>(
                    _ => new LocalProfileTokenProvider(profile));
                break;

            case AuthenticationProviderType.Auth0:
                var auth0Config = new Auth0AuthenticationConfiguration();
                services.AddSingleton <IProfileTokenProvider>(new PkceClient(auth0Config.Issuer, auth0Config.PkceClientId));
                break;

            case AuthenticationProviderType.IdentityServer:
                var idsConfig = new IdentityServerAuthenticationConfiguration();
                services.AddSingleton <IProfileTokenProvider>(new PkceClient(idsConfig.Issuer, idsConfig.PkceClientId));
                break;

            default:
                throw new InvalidOperationException("Unknown authentication provider type.");
            }

            return(services);
        }
Esempio n. 2
0
    public static IServiceCollection AddIdentityServerProfileTokenProvider(this IServiceCollection services)
    {
        services.AddAccessTokenProvider();

        var idsConfig = new IdentityServerAuthenticationConfiguration();

        services.AddSingleton <IProfileTokenProvider>(
            _ => new PkceProfileTokenProvider(idsConfig.Issuer, idsConfig.PkceClientId));

        return(services);
    }
        public static void ConfigureIdentityServerAuthentication(IdentityServerAuthenticationOptions identityServerAuthenticationOptions)
        {
            var identityServerAuthenticationConfiguration = new IdentityServerAuthenticationConfiguration();

            _configuration.GetSection(nameof(IdentityServerAuthenticationConfiguration)).Bind(identityServerAuthenticationConfiguration);

            identityServerAuthenticationOptions.Authority            = identityServerAuthenticationConfiguration.Authority;
            identityServerAuthenticationOptions.ApiName              = identityServerAuthenticationConfiguration.ApiName;
            identityServerAuthenticationOptions.ApiSecret            = identityServerAuthenticationConfiguration.ApiSecret;
            identityServerAuthenticationOptions.EnableCaching        = identityServerAuthenticationConfiguration.EnableCaching;
            identityServerAuthenticationOptions.RequireHttpsMetadata = identityServerAuthenticationConfiguration.RequireHttpsMetadata;
            identityServerAuthenticationOptions.SupportedTokens      = identityServerAuthenticationConfiguration.SupportedTokens;
        }