Esempio n. 1
0
 public virtual async Task <ClientDto> UpdateAsync(ClientUpdateInputDto clientUpdateInput)
 {
     return(await ClientAppService.UpdateAsync(clientUpdateInput));
 }
        public virtual async Task <ClientDto> UpdateAsync(ClientUpdateInputDto clientUpdateInput)
        {
            var client = await ClientRepository.GetAsync(clientUpdateInput.Id);

            #region Basic Property
            client.ConcurrencyStamp             = clientUpdateInput.Client.ConcurrencyStamp;
            client.ClientId                     = clientUpdateInput.Client.ClientId ?? client.ClientId;
            client.ClientUri                    = clientUpdateInput.Client.ClientUri ?? client.ClientUri;
            client.ClientName                   = clientUpdateInput.Client.ClientName ?? client.ClientName;
            client.AbsoluteRefreshTokenLifetime = clientUpdateInput.Client.AbsoluteRefreshTokenLifetime
                                                  ?? client.AbsoluteRefreshTokenLifetime;
            client.AccessTokenLifetime = clientUpdateInput.Client.AccessTokenLifetime
                                         ?? client.AccessTokenLifetime;
            client.AccessTokenType             = clientUpdateInput.Client.AccessTokenType ?? client.AccessTokenType;
            client.AllowAccessTokensViaBrowser = clientUpdateInput.Client.AllowAccessTokensViaBrowser
                                                 ?? client.AllowAccessTokensViaBrowser;
            client.AllowOfflineAccess = clientUpdateInput.Client.AllowOfflineAccess
                                        ?? client.AllowOfflineAccess;
            client.AllowPlainTextPkce               = clientUpdateInput.Client.AllowPlainTextPkce ?? client.AllowPlainTextPkce;
            client.AllowRememberConsent             = clientUpdateInput.Client.AllowRememberConsent ?? client.AllowRememberConsent;
            client.AlwaysIncludeUserClaimsInIdToken = clientUpdateInput.Client.AlwaysIncludeUserClaimsInIdToken
                                                      ?? client.AlwaysIncludeUserClaimsInIdToken;
            client.AlwaysSendClientClaims    = clientUpdateInput.Client.AlwaysSendClientClaims ?? client.AlwaysSendClientClaims;
            client.AuthorizationCodeLifetime = clientUpdateInput.Client.AuthorizationCodeLifetime
                                               ?? client.AuthorizationCodeLifetime;
            client.BackChannelLogoutSessionRequired = clientUpdateInput.Client.BackChannelLogoutSessionRequired
                                                      ?? client.BackChannelLogoutSessionRequired;

            client.BackChannelLogoutUri = clientUpdateInput.Client.BackChannelLogoutUri
                                          ?? client.BackChannelLogoutUri;
            client.ClientClaimsPrefix = clientUpdateInput.Client.ClientClaimsPrefix ?? client.ClientClaimsPrefix;
            client.ConsentLifetime    = clientUpdateInput.Client.ConsentLifetime ?? client.ConsentLifetime;
            client.Description        = clientUpdateInput.Client.Description ?? client.Description;
            client.DeviceCodeLifetime = clientUpdateInput.Client.DeviceCodeLifetime ?? client.DeviceCodeLifetime;
            client.Enabled            = clientUpdateInput.Client.Enabled ?? client.Enabled;
            client.EnableLocalLogin   = clientUpdateInput.Client.EnableLocalLogin ?? client.EnableLocalLogin;
            client.FrontChannelLogoutSessionRequired = clientUpdateInput.Client.FrontChannelLogoutSessionRequired
                                                       ?? client.FrontChannelLogoutSessionRequired;
            client.FrontChannelLogoutUri = clientUpdateInput.Client.FrontChannelLogoutUri ?? client.FrontChannelLogoutUri;

            client.IdentityTokenLifetime = clientUpdateInput.Client.IdentityTokenLifetime ?? client.IdentityTokenLifetime;
            client.IncludeJwtId          = clientUpdateInput.Client.IncludeJwtId ?? client.IncludeJwtId;
            client.LogoUri                = clientUpdateInput.Client.LogoUri ?? client.LogoUri;
            client.PairWiseSubjectSalt    = clientUpdateInput.Client.PairWiseSubjectSalt ?? client.PairWiseSubjectSalt;
            client.ProtocolType           = clientUpdateInput.Client.ProtocolType ?? client.ProtocolType;
            client.RefreshTokenExpiration = clientUpdateInput.Client.RefreshTokenExpiration ?? client.RefreshTokenExpiration;
            client.RefreshTokenUsage      = clientUpdateInput.Client.RefreshTokenUsage ?? client.RefreshTokenUsage;
            client.RequireClientSecret    = clientUpdateInput.Client.RequireClientSecret ?? client.RequireClientSecret;
            client.RequireConsent         = clientUpdateInput.Client.RequireConsent ?? client.RequireConsent;

            client.RequirePkce = clientUpdateInput.Client.RequirePkce ?? client.RequirePkce;
            client.SlidingRefreshTokenLifetime = clientUpdateInput.Client.SlidingRefreshTokenLifetime
                                                 ?? client.SlidingRefreshTokenLifetime;
            client.UpdateAccessTokenClaimsOnRefresh = clientUpdateInput.Client.UpdateAccessTokenClaimsOnRefresh
                                                      ?? client.UpdateAccessTokenClaimsOnRefresh;

            client.UserCodeType    = clientUpdateInput.Client.UserCodeType ?? client.UserCodeType;
            client.UserSsoLifetime = clientUpdateInput.Client.UserSsoLifetime ?? client.UserSsoLifetime;
            #endregion

            #region AllowScope

            client.RemoveAllScopes();
            foreach (var scope in clientUpdateInput.Client.AllowedScopes)
            {
                client.AddScope(scope.Scope);
            }

            #endregion

            #region RedirectUris

            client.RemoveAllRedirectUris();
            foreach (var redirect in clientUpdateInput.Client.RedirectUris)
            {
                client.AddRedirectUri(redirect.RedirectUri);
            }

            #endregion

            #region AllowedGrantTypes

            client.RemoveAllAllowedGrantTypes();
            foreach (var grantType in clientUpdateInput.Client.AllowedGrantTypes)
            {
                client.AddGrantType(grantType.GrantType);
            }

            #endregion

            #region AllowedCorsOrigins

            client.RemoveAllCorsOrigins();
            foreach (var corgOrigin in clientUpdateInput.Client.AllowedCorsOrigins)
            {
                client.AddCorsOrigin(corgOrigin.Origin);
            }

            #endregion

            #region PostLogoutRedirectUris

            client.RemoveAllPostLogoutRedirectUris();
            foreach (var logoutRedirect in clientUpdateInput.Client.PostLogoutRedirectUris)
            {
                client.AddPostLogoutRedirectUri(logoutRedirect.PostLogoutRedirectUri);
            }

            #endregion

            #region IdentityProviderRestrictions

            client.RemoveAllIdentityProviderRestrictions();
            foreach (var provider in clientUpdateInput.Client.IdentityProviderRestrictions)
            {
                client.AddIdentityProviderRestriction(provider.Provider);
            }

            #endregion

            client = await ClientRepository.UpdateAsync(client, true);

            return(ObjectMapper.Map <Client, ClientDto>(client));
        }