Exemple #1
0
        public async Task <IdentityServiceResult> UpdateLogoutRedirectUriAsync(TApplication app, string oldRedirectUri, string newRedirectUri, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (oldRedirectUri == null)
            {
                throw new ArgumentNullException(nameof(oldRedirectUri));
            }

            if (newRedirectUri == null)
            {
                throw new ArgumentNullException(nameof(newRedirectUri));
            }

            var existingRedirectUri = await RedirectUris
                                      .SingleAsync(ru => ru.ApplicationId.Equals(app.Id) && ru.Value.Equals(oldRedirectUri) && ru.IsLogout);

            existingRedirectUri.Value = newRedirectUri;

            return(IdentityServiceResult.Success);
        }
 public void StringToRedirectUris()
 {
     foreach (var redirectUri in ToLists(RedirectUrisString))
     {
         RedirectUris.Add(redirectUri);
     }
 }
Exemple #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();
 }
Exemple #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);
            }
        }
Exemple #6
0
 public virtual void AddRedirectUri([NotNull] string redirectUri)
 {
     RedirectUris.Add(new ClientRedirectUri()
     {
         ClientId    = Id,
         RedirectUri = redirectUri
     });
 }
Exemple #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)
                 ));
        }
Exemple #8
0
 public bool Valid()
 {
     return(!Id.NullOrEmpty() &&
            !Name.NullOrEmpty() &&
            !ClientSecrets.IsNullOrEmpty() &&
            !AllowedScopes.IsNullOrEmpty() &&
            !RedirectUris.IsNullOrEmpty() &&
            !PostLogoutRedirectUris.IsNullOrEmpty() &&
            !AllowedCorsOrigins.IsNullOrEmpty());
 }
Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #11
0
 /// <summary>
 /// 添加登录回跳Uri
 /// </summary>
 /// <param name="allowed"></param>
 public void AddRedirectUris(List <string> allowed)
 {
     if (RedirectUris == null)
     {
         RedirectUris = new List <ClientRedirectUri>();
     }
     RedirectUris.ForEach(x =>
     {
         x.IsDeleted = true;
     });
     RedirectUris.AddRange(allowed.Select(x => new ClientRedirectUri(x)));
 }
Exemple #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();
        }
Exemple #13
0
        public async Task <IEnumerable <string> > FindRegisteredLogoutUrisAsync(TApplication app, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            var redirectUris = await RedirectUris
                               .Where(ru => ru.ApplicationId.Equals(app.Id) && ru.IsLogout)
                               .Select(ru => ru.Value)
                               .ToListAsync(cancellationToken);

            return(redirectUris);
        }
Exemple #14
0
        public Task <IdentityServiceResult> RegisterLogoutRedirectUriAsync(TApplication app, string redirectUri, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (redirectUri == null)
            {
                throw new ArgumentNullException(nameof(redirectUri));
            }

            RedirectUris.Add(CreateRedirectUri(app, redirectUri, isLogout: true));

            return(Task.FromResult(IdentityServiceResult.Success));
        }
Exemple #15
0
        public async Task <IdentityServiceResult> UnregisterLogoutRedirectUriAsync(TApplication app, string redirectUri, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (redirectUri == null)
            {
                throw new ArgumentNullException(nameof(redirectUri));
            }

            var registeredUri = await RedirectUris
                                .SingleAsync(ru => ru.ApplicationId.Equals(app.Id) && ru.Value.Equals(redirectUri) && ru.IsLogout);

            RedirectUris.Remove(registeredUri);

            return(IdentityServiceResult.Success);
        }
Exemple #16
0
        public void SetSigninRedirectUris(IEnumerable <string> redirectUris)
        {
            if (RedirectUris == null)
            {
                RedirectUris = new List <string>();
            }

            foreach (var uri in redirectUris)
            {
                if (uri.StartsWith("http://") || uri.StartsWith("https://"))
                {
                    // add the uri specifically as given
                    RedirectUris.Add(uri);
                }
                else
                {
                    // otherwise add for for both HTTP & HTTPS since we don't know which one
                    RedirectUris.Add($"http://{uri}");
                    RedirectUris.Add($"https://{uri}");
                }
            }
        }
Exemple #17
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);
        }
Exemple #19
0
        //public List<string> GrantTypes { get; set; }

        public JwtPayload ToPayload()
        {
            var payload = new JwtPayload();

            int issuedDate = (int)(DateTime.UtcNow
                                   .Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                                   .TotalMilliseconds);

            var expireDate = (int)(DateTime.UtcNow.AddYears(1).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);

            payload["software_id"]                = Id;
            payload["iss"]                        = "http://tempuri.org/poet";
            payload["iat"]                        = issuedDate;
            payload["exp"]                        = expireDate;
            payload["client_name"]                = Application;
            payload["client_uri"]                 = ApplicationUrl;
            payload["logo_uri"]                   = LogoUri;
            payload["initiate_login_uri"]         = LoginUri;
            payload["redirect_uris"]              = $"[{string.Join(",", RedirectUris.Select(u => $"\"{u}\""))}]";
            payload["token_endpoint_auth_method"] = "client_secret_post";
            //payload["grant_types"] = $"[{string.Join(",", GrantTypes.Select(u => $"\"{u}\""))}]";

            return(payload);
        }
Exemple #20
0
 public virtual ClientRedirectUri FindRedirectUri(string uri)
 {
     return(RedirectUris.FirstOrDefault(r => r.RedirectUri == uri));
 }
Exemple #21
0
 public ClientRedirectUriDto FindRedirectUri(string uri)
 {
     return RedirectUris.FirstOrDefault(r => r.RedirectUri == uri);
 }
Exemple #22
0
 public void RemoveRedirectUri(string uri)
 {
     RedirectUris.RemoveAll(r => r.RedirectUri == uri);
 }
Exemple #23
0
 public void RemoveAllRedirectUris()
 {
     RedirectUris.Clear();
 }
Exemple #24
0
 public void AddRedirectUri([NotNull] string redirectUri)
 {
     RedirectUris.Add(new ClientRedirectUriDto(Id, redirectUri));
 }
Exemple #25
0
        public override async Task Execute()
        {
            await Authorize();

            if (string.IsNullOrEmpty(Id))
            {
                return;
            }
            Guid g;

            if (Guid.TryParse(Id, out g))
            {
                var apps = await SimpleClient.Apps();

                var app = (from a in apps.Response.Data where a.Id == g select a).FirstOrDefault();
                if (app == null)
                {
                    Log.Debug("Could not find app with the id:{0}", g);
                    return;
                }
                var updateApp = false;
                if (!string.IsNullOrEmpty(Name))
                {
                    app.Name  = Name;
                    updateApp = true;
                }
                if (!string.IsNullOrEmpty(Description))
                {
                    app.Description = Description;
                    updateApp       = true;
                }
                if (RedirectUris != null && RedirectUris.Length > 0)
                {
                    app.RedirectUris = RedirectUris.ToList();
                    updateApp        = true;
                }
                if (updateApp)
                {
                    var result = await SimpleClient.UpdateApp(app);

                    Log.Debug(result);
                }
                if (!string.IsNullOrEmpty(Image) && File.Exists(Image))
                {
                    Log.Debug("Updating app image");
                    var image       = File.ReadAllBytes(Image);
                    var fi          = new FileInfo(Image);
                    var imageResult = await SimpleClient.SaveImage(ImageEntities.Apps, g, image, fi.Name, "image/" + fi.Extension);

                    Log.Debug(imageResult);

                    if (imageResult.Success)
                    {
                        var images = await SimpleClient.GetImage(ImageEntities.Apps, g);

                        Log.Debug(images);
                    }
                }
            }
            else
            {
                Log.Debug("Invalid app id specified");
            }
            UpdateAuthorization();
        }
Exemple #26
0
 public virtual void RemoveAllRedirectUri()
 {
     RedirectUris.Clear();
 }
Exemple #27
0
 public void AddEmptyRedirectUrl() => RedirectUris.Add(new SimpleValue <string>(String.Empty));
Exemple #28
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());
        }
Exemple #29
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)
                 ));
        }
 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;
 }