Esempio n. 1
0
        public static IServiceCollection AddOktaMvcAuthentication(this IServiceCollection services, OktaConfig oktaConfig)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (oktaConfig.ClientIsPopulated())
            {
                services.AddAuthentication(options =>
                {
                    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme    = OktaDefaults.MvcAuthenticationScheme;
                })
                .AddCookie()
                .AddOktaMvc(new OktaMvcOptions
                {
                    OktaDomain            = oktaConfig.Domain,
                    ClientId              = oktaConfig.ClientId,
                    ClientSecret          = oktaConfig.ClientSecret,
                    AuthorizationServerId = oktaConfig.AuthorizationServerId ?? ""
                });
            }

            return(services);
        }