public void StringToPostLogoutRedirectUris()
 {
     foreach (var postLogout in ToLists(PostLogoutRedirectUrisString))
     {
         PostLogoutRedirectUris.Add(postLogout);
     }
 }
예제 #2
0
 public virtual object Clone()
 {
     return(new OAuthClient
     {
         ClientId = ClientId,
         ClientNames = ClientNames == null ? new List <OAuthTranslation>() : ClientNames.Select(c => (OAuthTranslation)c.Clone()).ToList(),
         ClientUris = ClientUris == null ? new List <OAuthTranslation>() : ClientUris.Select(c => (OAuthTranslation)c.Clone()).ToList(),
         LogoUris = LogoUris == null ? new List <OAuthTranslation>() : LogoUris.Select(c => (OAuthTranslation)c.Clone()).ToList(),
         PolicyUris = PolicyUris == null ? new List <OAuthTranslation>() : PolicyUris.Select(c => (OAuthTranslation)c.Clone()).ToList(),
         TosUris = TosUris == null ? new List <OAuthTranslation>() : TosUris.Select(c => (OAuthTranslation)c.Clone()).ToList(),
         CreateDateTime = CreateDateTime,
         JwksUri = JwksUri,
         RefreshTokenExpirationTimeInSeconds = RefreshTokenExpirationTimeInSeconds,
         UpdateDateTime = UpdateDateTime,
         TokenEndPointAuthMethod = TokenEndPointAuthMethod,
         TokenExpirationTimeInSeconds = TokenExpirationTimeInSeconds,
         Secrets = Secrets == null ? new List <ClientSecret>() : Secrets.Select(s => (ClientSecret)s.Clone()).ToList(),
         AllowedScopes = AllowedScopes == null ? new List <OAuthScope>() : AllowedScopes.Select(s => (OAuthScope)s.Clone()).ToList(),
         JsonWebKeys = JsonWebKeys == null ? new List <JsonWebKey>() : JsonWebKeys.Select(j => (JsonWebKey)j.Clone()).ToList(),
         GrantTypes = GrantTypes.ToList(),
         RedirectionUrls = RedirectionUrls.ToList(),
         PreferredTokenProfile = PreferredTokenProfile,
         TokenEncryptedResponseAlg = TokenEncryptedResponseAlg,
         TokenEncryptedResponseEnc = TokenEncryptedResponseEnc,
         TokenSignedResponseAlg = TokenSignedResponseAlg,
         ResponseTypes = ResponseTypes.ToList(),
         Contacts = Contacts.ToList(),
         SoftwareId = SoftwareId,
         SoftwareVersion = SoftwareVersion,
         PostLogoutRedirectUris = PostLogoutRedirectUris.ToList()
     });
 }
예제 #3
0
 public void ParseUrls()
 {
     RedirectUris           = RedirectUris.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
     AllowedCorsOrigins     = AllowedCorsOrigins.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
     FrontChannelLogoutUri  = FrontChannelLogoutUri.RemoveTrailingSlashIfNeeded();
     PostLogoutRedirectUris = PostLogoutRedirectUris.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
 }
예제 #4
0
        public async Task <Client> UpdateClientAsync(IConfigurationDbContext _configurationContext)
        {
            var updateClient = await _configurationContext.Clients.Include(a => a.AllowedScopes).Include(a => a.RedirectUris).Include(a => a.PostLogoutRedirectUris).Include(a => a.AllowedGrantTypes).Where(a => a.Id == id).FirstOrDefaultAsync();

            var newClientModel = new Client
            {
                ClientName             = ClientName,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            }.ToEntity();

            updateClient.ClientName = newClientModel.ClientName;
            updateClient.RedirectUris.Clear();
            updateClient.RedirectUris = newClientModel.RedirectUris;

            updateClient.PostLogoutRedirectUris.Clear();
            updateClient.PostLogoutRedirectUris = newClientModel.PostLogoutRedirectUris;

            updateClient.AllowedScopes.Clear();
            updateClient.AllowedScopes = newClientModel.AllowedScopes;

            try
            {
                _configurationContext.Clients.Update(updateClient);

                await _configurationContext.SaveChangesAsync();

                return(updateClient.ToModel());
            }
            catch (Exception)
            {
                return(null);
            }
        }
        internal async Task <Client> CreateImplicitClientAsync(IConfigurationDbContext _configurationContext)
        {
            var newClient = new Client
            {
                ClientId               = ClientId,
                ClientName             = ClientName,
                AllowedGrantTypes      = GrantTypes.Implicit,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            };

            try
            {
                _configurationContext.Clients.Add(newClient.ToEntity());

                await _configurationContext.SaveChangesAsync();

                return(newClient);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #6
0
 public virtual void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri)
 {
     PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri()
     {
         ClientId = Id,
         PostLogoutRedirectUri = postLogoutRedirectUri
     });
 }
예제 #7
0
        /// <summary>
        /// Returns true if Oauth2Client instances are equal
        /// </summary>
        /// <param name="other">Instance of Oauth2Client to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Oauth2Client other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     ClientId == other.ClientId ||
                     ClientId != null &&
                     ClientId.Equals(other.ClientId)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     AllowedGrantTypes == other.AllowedGrantTypes ||
                     AllowedGrantTypes != null &&
                     other.AllowedGrantTypes != null &&
                     AllowedGrantTypes.SequenceEqual(other.AllowedGrantTypes)
                 ) &&
                 (
                     RedirectUris == other.RedirectUris ||
                     RedirectUris != null &&
                     other.RedirectUris != null &&
                     RedirectUris.SequenceEqual(other.RedirectUris)
                 ) &&
                 (
                     AllowedCorsOrigins == other.AllowedCorsOrigins ||
                     AllowedCorsOrigins != null &&
                     other.AllowedCorsOrigins != null &&
                     AllowedCorsOrigins.SequenceEqual(other.AllowedCorsOrigins)
                 ) &&
                 (
                     PostLogoutRedirectUris == other.PostLogoutRedirectUris ||
                     PostLogoutRedirectUris != null &&
                     other.PostLogoutRedirectUris != null &&
                     PostLogoutRedirectUris.SequenceEqual(other.PostLogoutRedirectUris)
                 ) &&
                 (
                     AllowedScopes == other.AllowedScopes ||
                     AllowedScopes != null &&
                     other.AllowedScopes != null &&
                     AllowedScopes.SequenceEqual(other.AllowedScopes)
                 ) &&
                 (
                     AllowedOfflineAccess == other.AllowedOfflineAccess ||

                     AllowedOfflineAccess.Equals(other.AllowedOfflineAccess)
                 ));
        }
예제 #8
0
 public bool Valid()
 {
     return(!Id.NullOrEmpty() &&
            !Name.NullOrEmpty() &&
            !ClientSecrets.IsNullOrEmpty() &&
            !AllowedScopes.IsNullOrEmpty() &&
            !RedirectUris.IsNullOrEmpty() &&
            !PostLogoutRedirectUris.IsNullOrEmpty() &&
            !AllowedCorsOrigins.IsNullOrEmpty());
 }
예제 #9
0
        public override bool Equals(object obj)
        {
            var other = obj as ClientModel;

            if (other == null)
            {
                return(false);
            }

            var result =
                AbsoluteRefreshTokenLifetime.SafeEquals(other.AbsoluteRefreshTokenLifetime) &&
                AccessTokenLifetime.SafeEquals(other.AccessTokenLifetime) &&
                AccessTokenType.SafeEquals(other.AccessTokenType) &&
                AllowAccessTokensViaBrowser.SafeEquals(other.AllowAccessTokensViaBrowser) &&
                AllowedCorsOrigins.SafeListEquals(other.AllowedCorsOrigins) &&
                AllowedGrantTypes.SafeListEquals(other.AllowedGrantTypes) &&
                AllowedScopes.SafeListEquals(other.AllowedScopes) &&
                AllowOfflineAccess.SafeEquals(other.AllowOfflineAccess) &&
                AllowPlainTextPkce.SafeEquals(other.AllowPlainTextPkce) &&
                AllowRememberConsent.SafeEquals(other.AllowRememberConsent) &&
                AlwaysSendClientClaims.SafeEquals(other.AlwaysSendClientClaims) &&
                AuthorizationCodeLifetime.SafeEquals(other.AuthorizationCodeLifetime) &&
                BackChannelLogoutSessionRequired.SafeEquals(other.BackChannelLogoutSessionRequired) &&
                BackChannelLogoutUri.SafeEquals(other.BackChannelLogoutUri) &&
                Claims.SafeListEquals(other.Claims) &&
                ClientId.SafeEquals(other.ClientId) &&
                ClientName.SafeEquals(other.ClientName) &&
                ClientSecrets.SafeListEquals(other.ClientSecrets) &&
                ClientUri.SafeEquals(other.ClientUri) &&
                ConsentLifetime.SafeEquals(other.ConsentLifetime) &&
                Enabled.SafeEquals(other.Enabled) &&
                EnableLocalLogin.SafeEquals(other.EnableLocalLogin) &&
                FrontChannelLogoutSessionRequired.SafeEquals(other.FrontChannelLogoutSessionRequired) &&
                FrontChannelLogoutUri.SafeEquals(other.FrontChannelLogoutUri) &&
                IdentityProviderRestrictions.SafeListEquals(other.IdentityProviderRestrictions) &&
                IdentityTokenLifetime.SafeEquals(other.IdentityTokenLifetime) &&
                IncludeJwtId.SafeEquals(other.IncludeJwtId) &&
                LogoUri.SafeEquals(other.LogoUri) &&
                LogoutSessionRequired.SafeEquals(other.LogoutSessionRequired) &&
                LogoutUri.SafeEquals(other.LogoutUri) &&
                PostLogoutRedirectUris.SafeListEquals(other.PostLogoutRedirectUris) &&
                Properties.SafeEquals(other.Properties) &&
                ProtocolType.SafeEquals(other.ProtocolType) &&
                RedirectUris.SafeListEquals(other.RedirectUris) &&
                RefreshTokenExpiration.SafeEquals(other.RefreshTokenExpiration) &&
                RefreshTokenUsage.SafeEquals(other.RefreshTokenUsage) &&
                RequireClientSecret.SafeEquals(other.RequireClientSecret) &&
                RequireConsent.SafeEquals(other.RequireConsent) &&
                RequirePkce.SafeEquals(other.RequirePkce) &&
                SlidingRefreshTokenLifetime.SafeEquals(other.SlidingRefreshTokenLifetime) &&
                UpdateAccessTokenClaimsOnRefresh.SafeEquals(other.UpdateAccessTokenClaimsOnRefresh);

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (ClientId != null)
                {
                    hashCode = hashCode * 59 + ClientId.GetHashCode();
                }
                if (Name != null)
                {
                    hashCode = hashCode * 59 + Name.GetHashCode();
                }
                if (AllowedGrantTypes != null)
                {
                    hashCode = hashCode * 59 + AllowedGrantTypes.GetHashCode();
                }
                if (RedirectUris != null)
                {
                    hashCode = hashCode * 59 + RedirectUris.GetHashCode();
                }
                if (AllowedCorsOrigins != null)
                {
                    hashCode = hashCode * 59 + AllowedCorsOrigins.GetHashCode();
                }
                if (PostLogoutRedirectUris != null)
                {
                    hashCode = hashCode * 59 + PostLogoutRedirectUris.GetHashCode();
                }
                if (AllowedScopes != null)
                {
                    hashCode = hashCode * 59 + AllowedScopes.GetHashCode();
                }
                if (ClientSecrets != null)
                {
                    hashCode = hashCode * 59 + ClientSecrets.GetHashCode();
                }
                if (HashedClientSecrets != null)
                {
                    hashCode = hashCode * 59 + HashedClientSecrets.GetHashCode();
                }

                hashCode = hashCode * 59 + AllowedOfflineAccess.GetHashCode();

                hashCode = hashCode * 59 + AccessTokenLifetime.GetHashCode();

                hashCode = hashCode * 59 + IdentityTokenLifetime.GetHashCode();

                hashCode = hashCode * 59 + RequireConsent.GetHashCode();
                return(hashCode);
            }
        }
예제 #11
0
 /// <summary>
 /// 添加退出登录Uri
 /// </summary>
 /// <param name="allowed"></param>
 public void AddPostLogoutRedirectUris(List <string> allowed)
 {
     if (PostLogoutRedirectUris == null)
     {
         PostLogoutRedirectUris = new List <ClientPostLogoutRedirectUri>();
     }
     PostLogoutRedirectUris.ForEach(x =>
     {
         x.IsDeleted = true;
     });
     PostLogoutRedirectUris.AddRange(allowed.Select(x => new ClientPostLogoutRedirectUri(x)));
 }
예제 #12
0
        public void Filter(List <string> existingClientIds)
        {
            Clients = Clients.Where(x => !existingClientIds.Contains(x.ClientId)).ToList();

            ClientSecrets          = ClientSecrets.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            AllowedGrantTypes      = AllowedGrantTypes.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            RedirectUris           = RedirectUris.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            PostLogoutRedirectUris = PostLogoutRedirectUris.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            AllowedScopes          = AllowedScopes.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            Claims                       = Claims.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            AllowedCorsOrigins           = AllowedCorsOrigins.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            IdentityProviderRestrictions = IdentityProviderRestrictions.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
            Properties                   = Properties.Where(x => !existingClientIds.Contains(x.Client.ClientId)).ToList();
        }
예제 #13
0
        public void SetPostLogoutRedirectUris(IEnumerable <string> redirectUris)
        {
            if (PostLogoutRedirectUris == null)
            {
                PostLogoutRedirectUris = new List <string>();
            }

            foreach (var uri in redirectUris)
            {
                if (uri.StartsWith("http://") || uri.StartsWith("https://"))
                {
                    // add the uri specifically as given
                    PostLogoutRedirectUris.Add(uri);
                }
                else
                {
                    // otherwise add for for both HTTP & HTTPS since we don't know which one
                    PostLogoutRedirectUris.Add($"http://{uri}");
                    PostLogoutRedirectUris.Add($"https://{uri}");
                }
            }
        }
예제 #14
0
        public Client Client(
            bool requireConsent = false,
            bool allowAccessTokensViaBrowser = true,
            int accessTokenLifetime          = 43200)
        {
            var client = new Client
            {
                RequireConsent    = requireConsent,
                ClientId          = Id,
                ClientName        = Name,
                ClientSecrets     = new List <Secret>(),
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowedScopes     =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                },
                RedirectUris                = RedirectUris.ToList(),
                PostLogoutRedirectUris      = PostLogoutRedirectUris.ToList(),
                AllowedCorsOrigins          = AllowedCorsOrigins.ToList(),
                AllowAccessTokensViaBrowser = allowAccessTokensViaBrowser,
                AccessTokenLifetime         = accessTokenLifetime
            };

            foreach (string clientSecret in ClientSecrets)
            {
                client.ClientSecrets.Add(new Secret(clientSecret));
            }

            foreach (string allowedScope in AllowedScopes)
            {
                client.AllowedScopes.Add(allowedScope);
            }

            return(client);
        }
        public Client MapToClientEntity(string clientName)
        {
            var newClient = new Client
            {
                AllowedGrantTypes = GrantTypes.Code,
                ClientName        = clientName ?? Guid.NewGuid().ToString("N"),
                AllowedScopes     = DefaultScopes.Union(AllowedScopes).ToList(),
                AlwaysIncludeUserClaimsInIdToken = true,
                ClientId                         = $"CodeClientPKCE-{Guid.NewGuid():N}",
                ClientSecrets                    = new List <Secret>(),
                EnableLocalLogin                 = false,
                PostLogoutRedirectUris           = PostLogoutRedirectUris.ToList(),
                RedirectUris                     = RedirectUris.ToList(),
                UpdateAccessTokenClaimsOnRefresh = true,
                FrontChannelLogoutUri            = FrontChannelLogoutUri
            };

            if (AllowOfflineAccess == true)
            {
                newClient.AllowOfflineAccess           = true;
                newClient.AbsoluteRefreshTokenLifetime = Convert.ToInt32(TimeSpan.FromDays(OfflineAccessDurationInDays.Value).TotalSeconds);
                newClient.RefreshTokenUsage            = TokenUsage.ReUse;
                newClient.RefreshTokenExpiration       = TokenExpiration.Absolute;
            }

            if (AccessTokenLifetimeInSeconds.HasValue)
            {
                newClient.AccessTokenLifetime = AccessTokenLifetimeInSeconds.Value;
            }

            if (ShouldUseMfa)
            {
                newClient.Properties.Add(Constants.ShouldUseMfaKey, "true");
            }

            return(newClient);
        }
예제 #16
0
 public object Clone()
 {
     return(new OAuthClient
     {
         ClientId = ClientId,
         Translations = Translations == null ? new List <OAuthClientTranslation>() : Translations.Select(t => (OAuthClientTranslation)t.Clone()).ToList(),
         CreateDateTime = CreateDateTime,
         JwksUri = JwksUri,
         RefreshTokenExpirationTimeInSeconds = RefreshTokenExpirationTimeInSeconds,
         UpdateDateTime = UpdateDateTime,
         TokenEndPointAuthMethod = TokenEndPointAuthMethod,
         TokenExpirationTimeInSeconds = TokenExpirationTimeInSeconds,
         ClientSecret = ClientSecret,
         ClientSecretExpirationTime = ClientSecretExpirationTime,
         AllowedScopes = AllowedScopes == null ? new List <OAuthScope>() : AllowedScopes.Select(s => (OAuthScope)s.Clone()).ToList(),
         JsonWebKeys = JsonWebKeys == null ? new List <JsonWebKey>() : JsonWebKeys.Select(j => (JsonWebKey)j.Clone()).ToList(),
         GrantTypes = GrantTypes.ToList(),
         RedirectionUrls = RedirectionUrls.ToList(),
         PreferredTokenProfile = PreferredTokenProfile,
         TokenEncryptedResponseAlg = TokenEncryptedResponseAlg,
         TokenEncryptedResponseEnc = TokenEncryptedResponseEnc,
         TokenSignedResponseAlg = TokenSignedResponseAlg,
         ResponseTypes = ResponseTypes.ToList(),
         Contacts = Contacts.ToList(),
         SoftwareId = SoftwareId,
         SoftwareVersion = SoftwareVersion,
         RegistrationAccessToken = RegistrationAccessToken,
         PostLogoutRedirectUris = PostLogoutRedirectUris.ToList(),
         TlsClientAuthSanDNS = TlsClientAuthSanDNS,
         TlsClientAuthSanEmail = TlsClientAuthSanEmail,
         TlsClientAuthSanIP = TlsClientAuthSanIP,
         TlsClientAuthSanURI = TlsClientAuthSanURI,
         TlsClientAuthSubjectDN = TlsClientAuthSubjectDN,
         TlsClientCertificateBoundAccessToken = TlsClientCertificateBoundAccessToken
     });
 }
예제 #17
0
        internal IdentityServer4.EntityFramework.Entities.Client ToClient()
        {
            var redirectUris = RedirectUris?.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                               .Where(cors => !string.IsNullOrWhiteSpace(cors) && cors.IsUrl()).ToList();
            var allowedCorsOrigins = AllowedCorsOrigins?.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                     .Where(cors => !string.IsNullOrWhiteSpace(cors) && cors.IsUrl()).ToList();
            var client = new Models.Client
            {
                AbsoluteRefreshTokenLifetime = AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime          = AccessTokenLifetime,
                AccessTokenType             = AccessTokenType,
                AllowAccessTokensViaBrowser = AllowAccessTokensViaBrowser,
                AllowedCorsOrigins          = allowedCorsOrigins,
                AllowedGrantTypes           = GetAllowedGrantTypes(),
                AllowedScopes = AllowedScopes?.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                                .Where(cors => !string.IsNullOrWhiteSpace(cors)).ToList(),
                AllowOfflineAccess               = AllowOfflineAccess,
                AllowPlainTextPkce               = AllowPlainTextPkce,
                AllowRememberConsent             = AllowRememberConsent,
                AlwaysIncludeUserClaimsInIdToken = AlwaysIncludeUserClaimsInIdToken,
                AlwaysSendClientClaims           = AlwaysSendClientClaims,
                AuthorizationCodeLifetime        = AuthorizationCodeLifetime,
                BackChannelLogoutSessionRequired = BackChannelLogoutSessionRequired,
                BackChannelLogoutUri             = BackChannelLogoutUri,
                ClientClaimsPrefix               = ClientClaimsPrefix,
                ClientId           = ClientId,
                ClientName         = ClientName,
                ClientUri          = ClientUri,
                ConsentLifetime    = ConsentLifetime,
                Description        = Description,
                DeviceCodeLifetime = DeviceCodeLifetime,
                Enabled            = Enabled,
                EnableLocalLogin   = EnableLocalLogin,
                FrontChannelLogoutSessionRequired = FrontChannelLogoutSessionRequired,
                FrontChannelLogoutUri             = FrontChannelLogoutUri,
                IdentityProviderRestrictions      =
                    IdentityProviderRestrictions?.Split("\r\n", StringSplitOptions.RemoveEmptyEntries),
                IdentityTokenLifetime = IdentityTokenLifetime,
                IncludeJwtId          = IncludeJwtId,
                LogoUri                = LogoUri,
                PairWiseSubjectSalt    = PairWiseSubjectSalt,
                PostLogoutRedirectUris = PostLogoutRedirectUris?
                                         .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                         .Where(cors => !string.IsNullOrWhiteSpace(cors) && cors.IsUrl()).ToList(),
                // Properties
                ProtocolType                     = ProtocolType,
                RedirectUris                     = redirectUris,
                RefreshTokenExpiration           = RefreshTokenExpiration,
                RefreshTokenUsage                = RefreshTokenUsage,
                RequireClientSecret              = RequireClientSecret,
                RequireConsent                   = RequireConsent,
                RequirePkce                      = RequirePkce,
                SlidingRefreshTokenLifetime      = SlidingRefreshTokenLifetime,
                UpdateAccessTokenClaimsOnRefresh = UpdateAccessTokenClaimsOnRefresh,
                UserCodeType                     = UserCodeType,
                UserSsoLifetime                  = UserSsoLifetime,
            };

            var secrets = ClientSecrets?.Split("\r\n", StringSplitOptions.RemoveEmptyEntries)
                          .Select(x => new Secret(x.Sha256())).ToList();

            if (secrets != null && secrets.Count == 0)
            {
                client.ClientSecrets = secrets;
            }

            return(client.ToEntity());
        }
예제 #18
0
 public ClientPostLogoutRedirectUriDto FindPostLogoutRedirectUri(string uri)
 {
     return PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri);
 }
예제 #19
0
 public void RemovePostLogoutRedirectUri(string uri)
 {
     PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri);
 }
예제 #20
0
 public void RemoveAllPostLogoutRedirectUris()
 {
     PostLogoutRedirectUris.Clear();
 }
예제 #21
0
 public void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri)
 {
     PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUriDto(Id, postLogoutRedirectUri));
 }
예제 #22
0
 public virtual void RemoveAllPostLogoutRedirectUri()
 {
     PostLogoutRedirectUris.Clear();
 }
예제 #23
0
 public void AddEmptyPostRedirectUrl() => PostLogoutRedirectUris.Add(new SimpleValue <string>(String.Empty));
예제 #24
0
        /// <summary>
        /// Returns true if Oauth2ClientSubmit instances are equal
        /// </summary>
        /// <param name="other">Instance of Oauth2ClientSubmit to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Oauth2ClientSubmit other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     ClientId == other.ClientId ||
                     ClientId != null &&
                     ClientId.Equals(other.ClientId)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     AllowedGrantTypes == other.AllowedGrantTypes ||
                     AllowedGrantTypes != null &&
                     other.AllowedGrantTypes != null &&
                     AllowedGrantTypes.SequenceEqual(other.AllowedGrantTypes)
                 ) &&
                 (
                     RedirectUris == other.RedirectUris ||
                     RedirectUris != null &&
                     other.RedirectUris != null &&
                     RedirectUris.SequenceEqual(other.RedirectUris)
                 ) &&
                 (
                     AllowedCorsOrigins == other.AllowedCorsOrigins ||
                     AllowedCorsOrigins != null &&
                     other.AllowedCorsOrigins != null &&
                     AllowedCorsOrigins.SequenceEqual(other.AllowedCorsOrigins)
                 ) &&
                 (
                     PostLogoutRedirectUris == other.PostLogoutRedirectUris ||
                     PostLogoutRedirectUris != null &&
                     other.PostLogoutRedirectUris != null &&
                     PostLogoutRedirectUris.SequenceEqual(other.PostLogoutRedirectUris)
                 ) &&
                 (
                     AllowedScopes == other.AllowedScopes ||
                     AllowedScopes != null &&
                     other.AllowedScopes != null &&
                     AllowedScopes.SequenceEqual(other.AllowedScopes)
                 ) &&
                 (
                     ClientSecrets == other.ClientSecrets ||
                     ClientSecrets != null &&
                     other.ClientSecrets != null &&
                     ClientSecrets.SequenceEqual(other.ClientSecrets)
                 ) &&
                 (
                     HashedClientSecrets == other.HashedClientSecrets ||
                     HashedClientSecrets != null &&
                     other.HashedClientSecrets != null &&
                     HashedClientSecrets.SequenceEqual(other.HashedClientSecrets)
                 ) &&
                 (
                     AllowedOfflineAccess == other.AllowedOfflineAccess ||

                     AllowedOfflineAccess.Equals(other.AllowedOfflineAccess)
                 ) &&
                 (
                     AccessTokenLifetime == other.AccessTokenLifetime ||

                     AccessTokenLifetime.Equals(other.AccessTokenLifetime)
                 ) &&
                 (
                     IdentityTokenLifetime == other.IdentityTokenLifetime ||

                     IdentityTokenLifetime.Equals(other.IdentityTokenLifetime)
                 ) &&
                 (
                     RequireConsent == other.RequireConsent ||

                     RequireConsent.Equals(other.RequireConsent)
                 ));
        }
예제 #25
0
 public virtual ClientPostLogoutRedirectUri FindPostLogoutRedirectUri(string uri)
 {
     return(PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri));
 }
예제 #26
0
 public void UpdateEntity(IdentityServer4.EntityFramework.Entities.Client entity)
 {
     entity.Enabled                          = Enabled;
     entity.ClientId                         = ClientId;
     entity.ProtocolType                     = ProtocolType;
     entity.RequireClientSecret              = RequireClientSecret;
     entity.ClientName                       = ClientName;
     entity.Description                      = Description;
     entity.ClientUri                        = ClientUri;
     entity.LogoUri                          = LogoUri;
     entity.RequireConsent                   = RequireConsent;
     entity.AllowRememberConsent             = AllowRememberConsent;
     entity.AlwaysIncludeUserClaimsInIdToken = AlwaysIncludeUserClaimsInIdToken;
     entity.AllowedGrantTypes                = AllowedGrantTypes.Select(x => new ClientGrantType
     {
         GrantType = x,
     }).ToList();
     entity.RequirePkce                 = RequirePkce;
     entity.AllowPlainTextPkce          = AllowPlainTextPkce;
     entity.AllowAccessTokensViaBrowser = AllowAccessTokensViaBrowser;
     entity.RedirectUris                = RedirectUris.Select(x => new ClientRedirectUri
     {
         RedirectUri = x,
     }).ToList();
     entity.PostLogoutRedirectUris = PostLogoutRedirectUris.Select(x => new ClientPostLogoutRedirectUri
     {
         PostLogoutRedirectUri = x,
     }).ToList();
     entity.FrontChannelLogoutUri             = FrontChannelLogoutUri;
     entity.FrontChannelLogoutSessionRequired = FrontChannelLogoutSessionRequired;
     entity.BackChannelLogoutUri             = BackChannelLogoutUri;
     entity.BackChannelLogoutSessionRequired = BackChannelLogoutSessionRequired;
     entity.AllowOfflineAccess = AllowOfflineAccess;
     entity.AllowedScopes      = AllowedScopes.Select(x => new ClientScope
     {
         Scope = x,
     }).ToList();
     entity.IdentityTokenLifetime            = IdentityTokenLifetime;
     entity.AccessTokenLifetime              = AccessTokenLifetime;
     entity.AuthorizationCodeLifetime        = AuthorizationCodeLifetime;
     entity.ConsentLifetime                  = ConsentLifetime;
     entity.AbsoluteRefreshTokenLifetime     = AbsoluteRefreshTokenLifetime;
     entity.SlidingRefreshTokenLifetime      = SlidingRefreshTokenLifetime;
     entity.RefreshTokenUsage                = (int)RefreshTokenUsage;
     entity.UpdateAccessTokenClaimsOnRefresh = UpdateAccessTokenClaimsOnRefresh;
     entity.RefreshTokenExpiration           = (int)RefreshTokenExpiration;
     entity.AccessTokenType                  = (int)AccessTokenType;
     entity.EnableLocalLogin                 = EnableLocalLogin;
     entity.IdentityProviderRestrictions     = IdentityProviderRestrictions.Select(x => new ClientIdPRestriction
     {
         Provider = x,
     }).ToList();
     entity.IncludeJwtId           = IncludeJwtId;
     entity.AlwaysSendClientClaims = AlwaysSendClientClaims;
     entity.ClientClaimsPrefix     = ClientClaimsPrefix;
     entity.PairWiseSubjectSalt    = PairWiseSubjectSalt;
     entity.AllowedCorsOrigins     = AllowedCorsOrigins.Select(x => new ClientCorsOrigin
     {
         Origin = x,
     }).ToList();
     entity.UserSsoLifetime    = UserSsoLifetime;
     entity.UserCodeType       = UserCodeType;
     entity.DeviceCodeLifetime = DeviceCodeLifetime;
 }