Пример #1
0
        public ScopeDetailResource(ScopeDetail scope, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (idmAdminMeta == null)
            {
                throw new ArgumentNullException("idmAdminMeta");
            }

            Data = new ScopeDetailDataResource(scope, url, idmAdminMeta);

            var links = new Dictionary <string, string>();

            if (idmAdminMeta.ClientMetaData.SupportsDelete)
            {
                links["Delete"] = url.Link(Constants.RouteNames.DeleteScope, new { subject = scope.Subject });
            }
            Links = links;
        }
Пример #2
0
        public ClientDetailResource(ClientDetail client, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (idmAdminMeta == null)
            {
                throw new ArgumentNullException("idmAdminMeta");
            }

            Data = new ClientDetailDataResource(client, url, idmAdminMeta);

            var links = new Dictionary <string, string>();

            if (idmAdminMeta.ClientMetaData.SupportsDelete)
            {
                links["Delete"] = url.RelativeLink(Constants.RouteNames.DeleteClient, new { subject = client.Subject });
            }
            Links = links;
        }
Пример #3
0
        private async Task <IdentityAdminMetadata> GetMetadataAsync()
        {
            if (_metadata == null)
            {
                _metadata = await this._identityAdminService.GetMetadataAsync();

                if (_metadata == null)
                {
                    throw new InvalidOperationException("GetMetadataAsync returned null");
                }
                _metadata.Validate();
            }

            return(_metadata);
        }
Пример #4
0
        private IdentityAdminMetadata GetMetadata()
        {
            if (_metadata == null)
            {
                var updateClient = new List <PropertyMetadata>();
                updateClient.AddRange(PropertyMetadata.FromType <InMemoryClient>());

                var createClient = new List <PropertyMetadata>
                {
                    PropertyMetadata.FromProperty <InMemoryClient>(x => x.ClientName, "ClientName", required: true),
                    PropertyMetadata.FromProperty <InMemoryClient>(x => x.ClientId, "ClientId", required: true),
                };

                var client = new ClientMetaData
                {
                    SupportsCreate   = true,
                    SupportsDelete   = true,
                    CreateProperties = createClient,
                    UpdateProperties = updateClient
                };


                var updateScope = new List <PropertyMetadata>();
                updateScope.AddRange(PropertyMetadata.FromType <InMemoryScope>());

                var createScope = new List <PropertyMetadata>
                {
                    PropertyMetadata.FromProperty <InMemoryScope>(x => x.Name, "ScopeName", required: true),
                };

                var scope = new ScopeMetaData
                {
                    SupportsCreate   = true,
                    SupportsDelete   = true,
                    CreateProperties = createScope,
                    UpdateProperties = updateScope
                };


                _metadata = new IdentityAdminMetadata
                {
                    ClientMetaData = client,
                    ScopeMetaData  = scope
                };
            }
            return(_metadata);
        }
Пример #5
0
        private async Task <IdentityAdminMetadata> GetCoreMetaDataAsync()
        {
            if (_adminMetadata == null)
            {
                _adminMetadata = await _identityAdminService.GetMetadataAsync();

                if (_adminMetadata == null)
                {
                    throw new InvalidOperationException("coreMetaData returned null");
                }
                var scopeMetaData = _adminMetadata.ScopeMetaData;
                if (scopeMetaData == null)
                {
                    throw new InvalidOperationException("ScopeMetaData returned null");
                }
                scopeMetaData.Validate();

                return(_adminMetadata);
            }

            return(_adminMetadata);
        }
Пример #6
0
        private async Task <IdentityAdminMetadata> GetMetadataAsync()
        {
            if (_metadata == null)
            {
                var clientMetadata = await _clientService.GetMetadataAsync();

                var identityResourceMetaData = await _identityResourceService.GetMetadataAsync();

                var apiResourceMetaData = await _apiResourceService.GetMetadataAsync();

                if (clientMetadata == null)
                {
                    throw new InvalidOperationException("Client GetMetadataAsync returned null");
                }
                if (identityResourceMetaData == null)
                {
                    throw new InvalidOperationException("Identity Resource GetMetadataAsync returned null");
                }
                if (apiResourceMetaData == null)
                {
                    throw new InvalidOperationException("Api Resource GetMetadataAsync returned null");
                }

                _metadata = new IdentityAdminMetadata
                {
                    ClientMetaData           = clientMetadata,
                    IdentityResourceMetaData = identityResourceMetaData,
                    ApiResourceMetaData      = apiResourceMetaData
                };
                if (_metadata == null)
                {
                    throw new InvalidOperationException("GetMetadataAsync returned null");
                }
                _metadata.Validate();
            }

            return(_metadata);
        }
        public ClientDetailDataResource(ClientDetail client, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (idmAdminMeta == null)
            {
                throw new ArgumentNullException("idmAdminMeta");
            }

            this["ClientName"] = client.ClientName;
            this["ClientId"]   = client.ClientId;
            this["Subject"]    = client.Subject;

            if (client.Properties != null)
            {
                var props =
                    from p in client.Properties
                    let m =
                        (from m in idmAdminMeta.ClientMetaData.UpdateProperties where m.Type == p.Type select m).SingleOrDefault
                            ()
                        where m != null
                        select new
                {
                    Data  = m.Convert(p.Value),
                    Meta  = m,
                    Links = new
                    {
                        update = url.Link(Constants.RouteNames.UpdateClientProperty,
                                          new
                        {
                            subject = client.Subject,
                            type    = p.Type.ToBase64UrlEncoded()
                        }
                                          )
                    }
                };

                if (props.Any())
                {
                    this["Properties"] = props.ToArray();
                }
            }

            #region Claims
            if (client.Claims != null)
            {
                var claims =
                    from c in client.Claims.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientClaim, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["Claims"] = new
                {
                    Data  = claims.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientClaim, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region ClientSecrets
            if (client.ClientSecrets != null)
            {
                var clientSecrets =
                    from c in client.ClientSecrets.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientSecret, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["ClientSecrets"] = new
                {
                    Data  = clientSecrets.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientSecret, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region IdentityProviderRestrictions
            if (client.IdentityProviderRestrictions != null)
            {
                var clientIdentityProviderRestrictions =
                    from c in client.IdentityProviderRestrictions.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientIdPRestriction, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["IdentityProviderRestrictions"] = new
                {
                    Data  = clientIdentityProviderRestrictions.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientIdPRestriction, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region PostLogoutRedirectUris
            if (client.PostLogoutRedirectUris != null)
            {
                var postLogoutRedirectUris =
                    from c in client.PostLogoutRedirectUris.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientPostLogoutRedirectUri, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["PostLogoutRedirectUris"] = new
                {
                    Data  = postLogoutRedirectUris.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientPostLogoutRedirectUri, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region RedirectUris
            if (client.RedirectUris != null)
            {
                var redirectUris =
                    from c in client.RedirectUris.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientRedirectUri, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["RedirectUris"] = new
                {
                    Data  = redirectUris.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientRedirectUri, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region AllowedCorsOrigins
            if (client.AllowedCorsOrigins != null)
            {
                var alowedCorsOrigins =
                    from c in client.AllowedCorsOrigins.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientCorsOrigin, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["AllowedCorsOrigins"] = new
                {
                    Data  = alowedCorsOrigins.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientCorsOrigin, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region AllowedCustomGrantTypes
            if (client.AllowedCustomGrantTypes != null)
            {
                var allowedCustomGrantTypes =
                    from c in client.AllowedCustomGrantTypes.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientCustomGrantType, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["AllowedCustomGrantTypes"] = new
                {
                    Data  = allowedCustomGrantTypes.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientCustomGrantType, new { subject = client.Subject })
                    }
                };
            }
            #endregion

            #region AllowedScopes
            if (client.AllowedScopes != null)
            {
                var allowedScopes =
                    from c in client.AllowedScopes.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveClientScope, new
                        {
                            subject = client.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["AllowedScopes"] = new
                {
                    Data  = allowedScopes.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddClientScope, new { subject = client.Subject })
                    }
                };
            }
            #endregion
        }
 internal void SetupGetMetadataAsync(IdentityAdminMetadata data)
 {
     Setup(x => x.GetMetadataAsync())
     .Returns(Task.FromResult(data));
 }
        public ScopeDetailDataResource(ScopeDetail scope, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (idmAdminMeta == null)
            {
                throw new ArgumentNullException("idmAdminMeta");
            }

            this["Name"]        = scope.Name;
            this["Description"] = scope.Description;
            this["Subject"]     = scope.Subject;

            if (scope.Properties != null)
            {
                var props =
                    from p in scope.Properties
                    let m =
                        (from m in idmAdminMeta.ScopeMetaData.UpdateProperties where m.Type == p.Type select m).SingleOrDefault
                            ()
                        where m != null
                        select new
                {
                    Data  = m.Convert(p.Value),
                    Meta  = m,
                    Links = new
                    {
                        update = url.Link(Constants.RouteNames.UpdateScopeProperty,
                                          new
                        {
                            subject = scope.Subject,
                            type    = p.Type.ToBase64UrlEncoded()
                        }
                                          )
                    }
                };

                if (props.Any())
                {
                    this["Properties"] = props.ToArray();
                }
            }

            #region Claims
            if (scope.ScopeClaimValues != null)
            {
                var claimValues =
                    from c in scope.ScopeClaimValues.ToArray()
                    select new
                {
                    Data  = c,
                    Links = new
                    {
                        delete = url.Link(Constants.RouteNames.RemoveScopeClaim, new
                        {
                            subject = scope.Subject,
                            id      = c.Id
                        })
                    }
                };

                this["Claims"] = new
                {
                    Data  = claimValues.ToArray(),
                    Links = new
                    {
                        create = url.Link(Constants.RouteNames.AddScopeClaim, new { subject = scope.Subject })
                    }
                };
            }
            #endregion
        }