public static IApplicationBuilder UseIdentityServerAuthentication(this IApplicationBuilder app, IdentityServerAuthenticationOptions options)
        {
            var combinedOptions = CombinedAuthenticationOptions.FromIdentityServerAuthenticationOptions(options);

            app.UseIdentityServerAuthentication(combinedOptions);

            return(app);
        }
Exemplo n.º 2
0
        public static IApplicationBuilder UseIdentityServerAuthentication(this IApplicationBuilder app, IdentityServerAuthenticationOptions options)
        {
            var combinedOptions = new CombinedAuthenticationOptions();

            combinedOptions.TokenRetriever       = options.TokenRetriever;
            combinedOptions.AuthenticationScheme = options.AuthenticationScheme;

            switch (options.SupportedTokens)
            {
            case SupportedTokens.Jwt:
                combinedOptions.JwtBearerOptions = ConfigureJwt(options);
                break;

            case SupportedTokens.Reference:
                combinedOptions.IntrospectionOptions = ConfigureIntrospection(options);
                break;

            case SupportedTokens.Both:
                combinedOptions.JwtBearerOptions     = ConfigureJwt(options);
                combinedOptions.IntrospectionOptions = ConfigureIntrospection(options);
                break;

            default:
                throw new Exception("SupportedTokens has invalid value");
            }

            app.UseMiddleware <IdentityServerAuthenticationMiddleware>(app, combinedOptions);

            var allowedScopes = new List <string>();

            if (!string.IsNullOrWhiteSpace(options.ScopeName))
            {
                allowedScopes.Add(options.ScopeName);
            }

            if (options.AdditionalScopes != null && options.AdditionalScopes.Any())
            {
                allowedScopes.AddRange(options.AdditionalScopes);
            }

            if (allowedScopes.Any())
            {
                var scopeOptions = new ScopeValidationOptions
                {
                    AllowedScopes        = allowedScopes,
                    AuthenticationScheme = options.AuthenticationScheme
                };

                app.AllowScopes(scopeOptions);
            }

            return(app);
        }
        public static IApplicationBuilder UseIdentityServerAuthentication(this IApplicationBuilder app, CombinedAuthenticationOptions options)
        {
            app.UseMiddleware <IdentityServerAuthenticationMiddleware>(app, options);

            if (options.ScopeValidationOptions.AllowedScopes.Any())
            {
                app.AllowScopes(options.ScopeValidationOptions);
            }

            return(app);
        }