Example #1
0
        public async Task UpdateOpenIdSettingsAsync(OpenIdSettings openIdSettings)
        {
            var settings = await _siteService.GetSiteSettingsAsync();

            settings.Properties[nameof(OpenIdSettings)] = JObject.FromObject(openIdSettings);
            await _siteService.UpdateSiteSettingsAsync(settings);
        }
Example #2
0
        public IActionResult ExternalLoginSettings()
        {
            var model = Settings.GetByKey <OpenIdSettings>();

            if (model == null)
            {
                model = new OpenIdSettings();
            }
            return(View(model));
        }
Example #3
0
        public async Task <OpenIdSettings> GetOpenIdSettingsAsync()
        {
            var settings = await _siteService.GetSiteSettingsAsync();

            var result = settings.As <OpenIdSettings>();

            if (result == null)
            {
                result = new OpenIdSettings();
            }

            return(result);
        }
Example #4
0
        public bool IsValidOpenIdSettings(OpenIdSettings settings, ModelStateDictionary modelState)
        {
            if (settings == null)
            {
                modelState.AddModelError("", T["Settings are not stablished."]);
                return(false);
            }

            if (!settings.AllowAuthorizationCodeFlow && !settings.AllowClientCredentialsFlow &&
                !settings.AllowHybridFlow && !settings.AllowImplicitFlow && !settings.AllowPasswordFlow)
            {
                modelState.AddModelError("", T["At least one OpenID Connect flow must be enabled."]);
                return(false);
            }

            ValidateUrisSchema(new string[] { settings.Authority }, !settings.TestingModeEnabled, modelState, "Authority");
            ValidateUrisSchema(settings.Audiences, !settings.TestingModeEnabled, modelState, "Audience");

            if (!settings.TestingModeEnabled)
            {
                if (settings.CertificateStoreName == null)
                {
                    modelState.AddModelError("CertificateStoreName", T["A Certificate Store Name is required."]);
                }
                if (settings.CertificateStoreLocation == null)
                {
                    modelState.AddModelError("CertificateStoreLocation", T["A Certificate Store Location is required."]);
                }
                if (string.IsNullOrWhiteSpace(settings.CertificateThumbPrint))
                {
                    modelState.AddModelError("CertificateThumbPrint", T["A certificate is required when testing mode is disabled."]);
                }
                if (!modelState.IsValid)
                {
                    return(false);
                }

                var certificate = GetCertificate(settings.CertificateStoreLocation.Value, settings.CertificateStoreName.Value, settings.CertificateThumbPrint);
                if (certificate == null)
                {
                    modelState.AddModelError("CertificateThumbPrint", T["The certificate cannot be found."]);
                    return(false);
                }
                if (!certificate.HasPrivateKey)
                {
                    modelState.AddModelError("CertificateThumbPrint", T["The certificate doesn't contain the required private key."]);
                    return(false);
                }
                if (certificate.Archived)
                {
                    modelState.AddModelError("CertificateThumbPrint", T["The certificate is not valid because it is marked as archived."]);
                    return(false);
                }
                var now = DateTime.Now;
                if (certificate.NotBefore > now || certificate.NotAfter < now)
                {
                    modelState.AddModelError("CertificateThumbPrint", T["The certificate is not valid for current date."]);
                    return(false);
                }
            }

            if (settings.AllowPasswordFlow && !settings.EnableTokenEndpoint)
            {
                modelState.AddModelError("AllowPasswordFlow", T["Password Flow cannot be enabled if Token Endpoint is disabled"]);
                return(false);
            }
            if (settings.AllowClientCredentialsFlow && !settings.EnableTokenEndpoint)
            {
                modelState.AddModelError("AllowClientCredentialsFlow", T["Client Credentials Flow cannot be enabled if Token Endpoint is disabled"]);
                return(false);
            }
            if (settings.AllowAuthorizationCodeFlow && (!settings.EnableAuthorizationEndpoint || !settings.EnableTokenEndpoint))
            {
                modelState.AddModelError("AllowAuthorizationCodeFlow", T["Authorization Code Flow cannot be enabled if Authorization Endpoint and Token Endpoint are disabled"]);
                return(false);
            }
            if (settings.AllowHybridFlow && (!settings.EnableAuthorizationEndpoint || !settings.EnableTokenEndpoint))
            {
                modelState.AddModelError("AllowAuthorizationHybridFlow", T["Authorization Hybrid cannot be enabled if Authorization Endpoint and Token Endpoint are disabled"]);
                return(false);
            }
            if (settings.AllowRefreshTokenFlow)
            {
                if (!settings.EnableTokenEndpoint)
                {
                    modelState.AddModelError("AllowRefreshTokenFlow", T["Refresh Token Flow cannot be enabled if Token Endpoint is disabled"]);
                    return(false);
                }
                if (!settings.AllowPasswordFlow && !settings.AllowAuthorizationCodeFlow && !settings.AllowHybridFlow)
                {
                    modelState.AddModelError("AllowRefreshTokenFlow", T["Refresh Token Flow only can be enabled if Password Flow, Authorization Code Flow or Hybrid Flow are enabled"]);
                    return(false);
                }
            }
            if (settings.AllowImplicitFlow && !settings.EnableAuthorizationEndpoint)
            {
                modelState.AddModelError("AllowImplicitFlow", T["Allow Implicit Flow cannot be enabled if Authorization Endpoint is disabled"]);
                return(false);
            }
            return(modelState.IsValid);
        }
Example #5
0
        public bool IsValidOpenIdSettings(OpenIdSettings settings)
        {
            var modelState = new ModelStateDictionary();

            return(IsValidOpenIdSettings(settings, modelState));
        }
Example #6
0
 public IActionResult ExternalLoginSettings(OpenIdSettings model)
 {
     Settings.SetByKey(model);
     ShowMessage("Settings save successful", MessageType.Success);
     return(View(model));
 }