public static AuthenticationInformationBuilder UseAuthenticationProvider(
            this AuthenticationInformationBuilder builder,
            AuthenticationProviderConfiguration configuration)
        {
            var parameters = builder.AuthenticationInformation.TokenValidationParameters;

            builder.AuthenticationInformation.Issuer = configuration.Issuer;
            builder.AuthenticationInformation.AuthorizationEndpoint = configuration.AuthorizationEndpoint;
            builder.AuthenticationInformation.TokenEndpoint         = configuration.TokenEndpoint;

            builder.AuthenticationInformation.ServiceClientId     = configuration.ServiceClientId;
            builder.AuthenticationInformation.ServiceClientSecret = configuration.ServiceClientSecret;

            parameters.ValidAudiences           = new[] { configuration.Audience };
            parameters.ValidIssuer              = configuration.Issuer;
            parameters.IssuerSigningKey         = null;
            parameters.IssuerSigningKeyResolver = (token, securityToken, kid, parameters) =>
            {
                var configurationManager = new ConfigurationManager <OpenIdConnectConfiguration>($"{parameters.ValidIssuer}.well-known/openid-configuration", new OpenIdConnectConfigurationRetriever());
                var openIdConfig         = configurationManager.GetConfigurationAsync(CancellationToken.None).GetAwaiter().GetResult();

                return(openIdConfig.SigningKeys);
            };

            return(builder);
        }
        public static AuthenticationInformationBuilder UseLocalProvider(this AuthenticationInformationBuilder builder)
        {
            builder.UseAuthenticationProvider(new LocalAuthenticationConfiguration());

            var parameters = builder.AuthenticationInformation.TokenValidationParameters;

            parameters.IssuerSigningKeyResolver = null;
            parameters.IssuerSigningKey         = LocalAuthentication.SecurityKey;

            return(builder);
        }
        public static IServiceCollection AddTyrApiAuthentication(this IServiceCollection services)
        {
            var profileAuthentication = new AuthenticationInformationBuilder()
                                        .UseAuth0Provider()
                                        .Build();

            var serviceAuthentication = new AuthenticationInformationBuilder()
                                        .UseIdentityServerProvider()
                                        .Build();

            return(services.AddTypingRealmAuthentication(profileAuthentication, serviceAuthentication)
                   .UseAspNetAuthentication(profileAuthentication, serviceAuthentication));
        }
        // TODO: Move it to separate assembly, not related to AspNet.
        public static MessageTypeCacheBuilder AddTyrServiceWithoutAspNetAuthentication(this MessageTypeCacheBuilder builder)
        {
            var profileAuthentication = new AuthenticationInformationBuilder()
                                        .UseAuth0Provider()
                                        .Build();

            var serviceAuthentication = new AuthenticationInformationBuilder()
                                        .UseIdentityServerProvider()
                                        .Build();

            builder.AddTypingRealmAuthentication(profileAuthentication, serviceAuthentication)
            .Services
            .UseConnectedClientContextAuthentication()
            .UseCharacterAuthorizationOnConnect();

            return(builder);
        }
 public static AuthenticationInformationBuilder UseIdentityServerProvider(this AuthenticationInformationBuilder builder)
 {
     return(builder.UseAuthenticationProvider(new IdentityServerAuthenticationConfiguration()));
 }
 public static AuthenticationInformationBuilder UseAuth0Provider(this AuthenticationInformationBuilder builder)
 {
     return(builder.UseAuthenticationProvider(new Auth0AuthenticationConfiguration()));
 }