public static AuthenticationBuilder AddMyApiProtection(this AuthenticationBuilder authBuilder, MyIdentityOptions identityOptions, IConfiguration config)
        {
            var apiScope = Constants.ApiScope;

            var urlsOptions = config.GetSection("urls").Get <MyUrlsOptions>();

            if (!string.IsNullOrWhiteSpace(urlsOptions.BaseUrl))
            {
                string apiAuthorityUrl;

                if (!string.IsNullOrWhiteSpace(identityOptions.AuthorityUrl))
                {
                    apiAuthorityUrl = identityOptions.AuthorityUrl.BuildFullUrl(Constants.IdentityPrefix);
                }
                else
                {
                    apiAuthorityUrl = urlsOptions.BuildUrl(Constants.IdentityPrefix);
                }

                authBuilder.AddIdentityServerAuthentication(options =>
                {
                    options.Authority            = apiAuthorityUrl;
                    options.ApiName              = apiScope;
                    options.ApiSecret            = null;
                    options.RequireHttpsMetadata = identityOptions.RequiresHttps;
                });
            }

            return(authBuilder);
        }
        public static AuthenticationBuilder AddMyGoogleAuthentication(this AuthenticationBuilder authBuilder, MyIdentityOptions identityOptions)
        {
            if (identityOptions.IsGoogleAuthConfigured())
            {
                authBuilder.AddGoogle(options =>
                {
                    options.ClientId     = identityOptions.GoogleClient;
                    options.ClientSecret = identityOptions.GoogleSecret;
                    options.Events       = new GoogleHandler();
                });
            }

            return(authBuilder);
        }
Exemple #3
0
        public static AuthenticationBuilder AddMyMicrosoftAuthentication(this AuthenticationBuilder authBuilder, MyIdentityOptions identityOptions)
        {
            if (identityOptions.IsMicrosoftAuthConfigured())
            {
                authBuilder.AddMicrosoftAccount(options =>
                {
                    options.ClientId     = identityOptions.MicrosoftClient;
                    options.ClientSecret = identityOptions.MicrosoftSecret;
                    options.Events       = new MicrosoftHandler();
                });
            }

            return(authBuilder);
        }