public async Task UpdateClient(string id, OutbackClient updatedClient)
        {
            var client = await _outbackDbContext.Clients.Where(m => m.ClientId == id)
                         .Include(m => m.AllowedCorsOrigins)
                         .Include(m => m.ClientClaims)
                         .Include(m => m.ClientFamily)
                         .Include(m => m.LoginRedirectUris)
                         .Include(m => m.PostLogoutRedirectUris)
                         .Include(m => m.Scopes)
                         .Include(m => m.Secrets)
                         .Include(m => m.SupportedGrantTypes).SingleOrDefaultAsync();

            if (ClientPropertiesEquals(client, updatedClient))
            {
                UpdateClientProperties(client, updatedClient);
            }

            UpdateAllowedCorsOrigins(client, updatedClient);
            UpdateClientClaims(client, updatedClient);
            UpdateLoginRedirectUris(client, updatedClient);
            UpdatePostLogoutRedirectUris(client, updatedClient);
            UpdateScopes(client, updatedClient);
            UpdateSecrets(client, updatedClient);
            UpdateSupportedGrantTypes(client, updatedClient);

            await _outbackDbContext.SaveChangesAsync();
        }
Exemple #2
0
        private async Task <string> CreateInnovationBoostSpaClient()
        {
            if (await _outbackDbContext.Clients.AnyAsync(m => m.Name == "InnovationBoostAdminApp"))
            {
                return(string.Empty);
            }

            var clientFamily = await _outbackDbContext.ClientFamilies.SingleAsync(m => m.Name == "SpaApplication");

            var scopes = await _outbackDbContext.Scopes.ToListAsync();

            var client = new OutbackClient
            {
                ClientFamilyId = clientFamily.Id,
                ClientType     = Rinsen.Outback.Clients.ClientType.Public,
                ClientId       = Guid.NewGuid().ToString(),
                Name           = "InnovationBoostAdminApp",
                AddUserInfoClaimsInIdentityToken = true,
                SupportedGrantTypes = new List <OutbackClientSupportedGrantType>
                {
                    new OutbackClientSupportedGrantType {
                        GrantType = "authorization_code"
                    }
                },
                Scopes = new List <OutbackClientScope>
                {
                    new OutbackClientScope
                    {
                        ScopeId = scopes.Single(m => m.ScopeName == "openid").Id,
                    },
                    new OutbackClientScope
                    {
                        ScopeId = scopes.Single(m => m.ScopeName == "profile").Id,
                    }
                },
                AllowedCorsOrigins = new List <OutbackClientAllowedCorsOrigin>
                {
                    new OutbackClientAllowedCorsOrigin
                    {
                        Origin      = "http://localhost:4200",
                        Description = "Debug origin"
                    }
                },
                LoginRedirectUris = new List <OutbackClientLoginRedirectUri>
                {
                    new OutbackClientLoginRedirectUri
                    {
                        LoginRedirectUri = "http://localhost:4200/index.html",
                        Description      = "Debug uri"
                    }
                }
            };

            await _outbackDbContext.AddAsync(client);

            await _outbackDbContext.SaveChangesAsync();

            return(client.ClientId);
        }
        public async Task CreateNewClient(string clientId, string clientName, string description, int familyId, ClientType clientType)
        {
            var outbackClient = new OutbackClient
            {
                ClientId       = clientId,
                ClientType     = clientType,
                Description    = description,
                Name           = clientName,
                ClientFamilyId = familyId
            };

            await _outbackDbContext.AddAsync(outbackClient);

            await _outbackDbContext.SaveChangesAsync();
        }
 private static void UpdateClientProperties(OutbackClient client, OutbackClient updatedClient)
 {
     client.AccessTokenLifetime   = updatedClient.AccessTokenLifetime;
     client.AuthorityCodeLifetime = updatedClient.AccessTokenLifetime;
     client.ClientFamilyId        = updatedClient.ClientFamilyId;
     client.ClientType            = updatedClient.ClientType;
     client.ClientId              = updatedClient.ClientId;
     client.ConsentRequired       = updatedClient.ConsentRequired;
     client.Description           = updatedClient.Description;
     client.IdentityTokenLifetime = updatedClient.IdentityTokenLifetime;
     client.IssueRefreshToken     = updatedClient.IssueRefreshToken;
     client.Name                 = updatedClient.Name;
     client.SaveConsent          = updatedClient.SaveConsent;
     client.SavedConsentLifetime = updatedClient.SavedConsentLifetime;
 }
 private static bool ClientPropertiesEquals(OutbackClient client, OutbackClient updatedClient)
 {
     return(client.AccessTokenLifetime == updatedClient.AccessTokenLifetime &&
            client.AuthorityCodeLifetime == updatedClient.AccessTokenLifetime &&
            client.ClientFamilyId == updatedClient.ClientFamilyId &&
            client.ClientId == updatedClient.ClientId &&
            client.ClientType == updatedClient.ClientType &&
            client.ConsentRequired == updatedClient.ConsentRequired &&
            client.Description == updatedClient.Description &&
            client.IdentityTokenLifetime == updatedClient.IdentityTokenLifetime &&
            client.IssueRefreshToken == updatedClient.IssueRefreshToken &&
            client.Name == updatedClient.Name &&
            client.SaveConsent == updatedClient.SaveConsent &&
            client.SavedConsentLifetime == updatedClient.SavedConsentLifetime);
 }
        private void UpdateClientClaims(OutbackClient client, OutbackClient updatedClient)
        {
            var existingClientClaims = new List <OutbackClientClaim>();

            foreach (var clientClaim in updatedClient.ClientClaims)
            {
                var existingClientClaim = client.ClientClaims.SingleOrDefault(m => m.Type == clientClaim.Type);

                if (existingClientClaim == default)
                {
                    var newClientClaim = new OutbackClientClaim
                    {
                        Type        = clientClaim.Type,
                        Description = clientClaim.Description,
                        Value       = clientClaim.Value
                    };

                    client.ClientClaims.Add(newClientClaim);
                    existingClientClaims.Add(newClientClaim);
                }
                else
                {
                    if (existingClientClaim.Deleted != null)
                    {
                        existingClientClaim.Deleted = null;
                    }

                    if (existingClientClaim.Description != clientClaim.Description ||
                        existingClientClaim.Value != clientClaim.Value)
                    {
                        existingClientClaim.Description = clientClaim.Description;
                        existingClientClaim.Value       = clientClaim.Value;
                    }

                    existingClientClaims.Add(existingClientClaim);
                }
            }

            var existingClientClaimsToDelete = client.ClientClaims.Except(existingClientClaims).ToList();

            if (existingClientClaimsToDelete.Any())
            {
                _outbackDbContext.ClientClaims.RemoveRange(existingClientClaimsToDelete);
            }
        }
        private void UpdatePostLogoutRedirectUris(OutbackClient client, OutbackClient updatedClient)
        {
            var existingPostLogoutRedirectUris = new List <OutbackClientPostLogoutRedirectUri>();

            foreach (var postLogoutRedirectUri in updatedClient.PostLogoutRedirectUris)
            {
                var existingPostLogoutRedirectUri = client.PostLogoutRedirectUris.SingleOrDefault(m => m.PostLogoutRedirectUri == postLogoutRedirectUri.PostLogoutRedirectUri);

                if (existingPostLogoutRedirectUri == default)
                {
                    var newPostLogoutRedirectUri = new OutbackClientPostLogoutRedirectUri
                    {
                        Description           = postLogoutRedirectUri.Description,
                        PostLogoutRedirectUri = postLogoutRedirectUri.PostLogoutRedirectUri
                    };

                    client.PostLogoutRedirectUris.Add(newPostLogoutRedirectUri);
                    existingPostLogoutRedirectUris.Add(newPostLogoutRedirectUri);
                }
                else
                {
                    if (existingPostLogoutRedirectUri.Deleted != null)
                    {
                        existingPostLogoutRedirectUri.Deleted = null;
                    }

                    if (existingPostLogoutRedirectUri.Description != postLogoutRedirectUri.Description ||
                        existingPostLogoutRedirectUri.PostLogoutRedirectUri != postLogoutRedirectUri.PostLogoutRedirectUri)
                    {
                        existingPostLogoutRedirectUri.Description           = postLogoutRedirectUri.Description;
                        existingPostLogoutRedirectUri.PostLogoutRedirectUri = postLogoutRedirectUri.PostLogoutRedirectUri;
                    }

                    existingPostLogoutRedirectUris.Add(existingPostLogoutRedirectUri);
                }
            }

            var existingPostLogoutRedirectUrisToDelete = client.PostLogoutRedirectUris.Except(existingPostLogoutRedirectUris).ToList();

            if (existingPostLogoutRedirectUrisToDelete.Any())
            {
                _outbackDbContext.ClientPostLogoutRedirectUris.RemoveRange(existingPostLogoutRedirectUrisToDelete);
            }
        }
Exemple #8
0
        private async Task <Credentials> CreateInnovationBoostWebClient()
        {
            if (await _outbackDbContext.Clients.AnyAsync(m => m.Name == "InnovationBoost"))
            {
                return(new Credentials());
            }

            var clientFamily = await _outbackDbContext.ClientFamilies.SingleAsync(m => m.Name == "WebApplication");

            var secret = GetClientSecret();

            var client = new OutbackClient
            {
                ClientFamilyId      = clientFamily.Id,
                ClientId            = GetClientId(),
                ClientType          = Rinsen.Outback.Clients.ClientType.Confidential,
                Name                = "InnovationBoost",
                SupportedGrantTypes = new List <OutbackClientSupportedGrantType>
                {
                    new OutbackClientSupportedGrantType {
                        GrantType = "client_credentials"
                    }
                },
                Secrets = new List <OutbackClientSecret>
                {
                    new OutbackClientSecret
                    {
                        Description = "Initial secret created by installer",
                        Secret      = HashHelper.GetSha256Hash(secret),
                    }
                },
                Scopes = new List <OutbackClientScope>()
            };

            await _outbackDbContext.AddAsync(client);

            await _outbackDbContext.SaveChangesAsync();

            return(new Credentials
            {
                ClientId = client.ClientId,
                Secret = secret
            });
        }
        private void UpdateSecrets(OutbackClient client, OutbackClient updatedClient)
        {
            var existingScopes = new List <OutbackClientSecret>();

            foreach (var secret in updatedClient.Secrets)
            {
                var existingSecret = client.Secrets.SingleOrDefault(m => m.Id == secret.Id);

                if (existingSecret == default)
                {
                    var newSecret = new OutbackClientSecret
                    {
                        Description = secret.Description,
                        Secret      = HashHelper.GetSha256Hash(secret.Secret)
                    };

                    client.Secrets.Add(newSecret);
                    existingScopes.Add(newSecret);
                }
                else
                {
                    if (existingSecret.Deleted != null)
                    {
                        existingSecret.Deleted = null;
                    }

                    if (existingSecret.Description != secret.Description)
                    {
                        existingSecret.Description = secret.Description;
                    }

                    existingScopes.Add(existingSecret);
                }
            }

            var existingSecretsToDelete = client.Secrets.Except(existingScopes).ToList();

            if (existingSecretsToDelete.Any())
            {
                _outbackDbContext.ClientSecrets.RemoveRange(existingSecretsToDelete);
            }
        }
        private void UpdateAllowedCorsOrigins(OutbackClient client, OutbackClient updatedClient)
        {
            var existingAllowedCorsOrigins = new List <OutbackClientAllowedCorsOrigin>();

            foreach (var allowedCorsOrigin in updatedClient.AllowedCorsOrigins)
            {
                var existingAllowedCorsOrigin = client.AllowedCorsOrigins.SingleOrDefault(m => m.Origin == allowedCorsOrigin.Origin);

                if (existingAllowedCorsOrigin == default)
                {
                    var newAllowedCorsOrigin = new OutbackClientAllowedCorsOrigin
                    {
                        Origin      = allowedCorsOrigin.Origin,
                        Description = allowedCorsOrigin.Description
                    };

                    client.AllowedCorsOrigins.Add(newAllowedCorsOrigin);
                    existingAllowedCorsOrigins.Add(newAllowedCorsOrigin);
                }
                else
                {
                    if (existingAllowedCorsOrigin.Deleted != null)
                    {
                        existingAllowedCorsOrigin.Deleted = null;
                    }

                    if (existingAllowedCorsOrigin.Description != allowedCorsOrigin.Description)
                    {
                        existingAllowedCorsOrigin.Description = allowedCorsOrigin.Description;
                    }

                    existingAllowedCorsOrigins.Add(existingAllowedCorsOrigin);
                }
            }

            var allowedCorsOriginsToDelete = client.AllowedCorsOrigins.Except(existingAllowedCorsOrigins).ToList();

            if (allowedCorsOriginsToDelete.Any())
            {
                _outbackDbContext.AllowedCorsOrigins.RemoveRange(allowedCorsOriginsToDelete);
            }
        }
        private void UpdateSupportedGrantTypes(OutbackClient client, OutbackClient updatedClient)
        {
            var existingGrantTypes = new List <OutbackClientSupportedGrantType>();

            foreach (var grantType in updatedClient.SupportedGrantTypes)
            {
                var existingGrantType = client.SupportedGrantTypes.SingleOrDefault(m => m.GrantType == grantType.GrantType);

                if (existingGrantType == default)
                {
                    var newGrant = new OutbackClientSupportedGrantType
                    {
                        GrantType = grantType.GrantType
                    };

                    client.SupportedGrantTypes.Add(newGrant);
                    existingGrantTypes.Add(newGrant);
                }
                else
                {
                    if (existingGrantType.Deleted != null)
                    {
                        existingGrantType.Deleted = null;
                    }

                    existingGrantTypes.Add(existingGrantType);
                }
            }

            var supportedGrantTypeToDelete = client.SupportedGrantTypes.Except(existingGrantTypes).ToList();

            if (supportedGrantTypeToDelete.Any())
            {
                _outbackDbContext.ClientSupportedGrantTypes.RemoveRange(supportedGrantTypeToDelete);
            }
        }
        private void UpdateScopes(OutbackClient client, OutbackClient updatedClient)
        {
            var existingScopes = new List <OutbackClientScope>();

            foreach (var scope in updatedClient.Scopes)
            {
                var existingScope = client.Scopes.SingleOrDefault(m => m.ScopeId == scope.ScopeId);

                if (existingScope == default)
                {
                    var newScope = new OutbackClientScope
                    {
                        ScopeId = scope.ScopeId
                    };

                    client.Scopes.Add(newScope);
                    existingScopes.Add(newScope);
                }
                else
                {
                    if (existingScope.Deleted != null)
                    {
                        existingScope.Deleted = null;
                    }

                    existingScopes.Add(existingScope);
                }
            }

            var existingScopesToDelete = client.Scopes.Except(existingScopes).ToList();

            if (existingScopesToDelete.Any())
            {
                _outbackDbContext.ClientScopes.RemoveRange(existingScopesToDelete);
            }
        }
        public async Task <ActionResult> Update(string id, [FromBody][Required] OutbackClient client)
        {
            await _clientService.UpdateClient(id, client);

            return(Ok());
        }
Exemple #14
0
        private async Task CreateOpenIdConnectSampleClient(Credentials creadentials)
        {
            if (await _outbackDbContext.Clients.AnyAsync(m => m.Name == "OpenIdConnectSample"))
            {
                return;
            }

            var clientFamily = await _outbackDbContext.ClientFamilies.SingleAsync(m => m.Name == "WebApplication");

            var scopes = await _outbackDbContext.Scopes.ToListAsync();

            var secret = _randomStringGenerator.GetRandomString(30);

            var client = new OutbackClient
            {
                ClientFamilyId      = clientFamily.Id,
                ClientId            = Guid.NewGuid().ToString(),
                ClientType          = Rinsen.Outback.Clients.ClientType.Confidential,
                Name                = "OpenIdConnectSample",
                SupportedGrantTypes = new List <OutbackClientSupportedGrantType>
                {
                    new OutbackClientSupportedGrantType {
                        GrantType = "authorization_code"
                    }
                },
                Secrets = new List <OutbackClientSecret>
                {
                    new OutbackClientSecret
                    {
                        Description = "Initial secret created by installer",
                        Secret      = HashHelper.GetSha256Hash(secret),
                    }
                },
                Scopes = new List <OutbackClientScope>
                {
                    new OutbackClientScope
                    {
                        ScopeId = scopes.Single(m => m.ScopeName == "openid").Id,
                    },
                    new OutbackClientScope
                    {
                        ScopeId = scopes.Single(m => m.ScopeName == "profile").Id,
                    }
                },
                LoginRedirectUris = new List <OutbackClientLoginRedirectUri>
                {
                    new OutbackClientLoginRedirectUri
                    {
                        Description      = "Debug redirect",
                        LoginRedirectUri = "https://localhost:44371/signin-oidc"
                    }
                }
            };

            await _outbackDbContext.AddAsync(client);

            await _outbackDbContext.SaveChangesAsync();

            creadentials.SampleClientId = client.ClientId;
            creadentials.SampleSecret   = secret;
        }