Esempio n. 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (IdentityServer != null ? IdentityServer.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ClientScope != null ? ClientScope.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ClientSecret != null ? ClientSecret.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public bool TryGet(string realm, out IdentityServer.Models.RelyingParty relyingParty)
        {
            relyingParty = new IdentityServer.Models.RelyingParty
            {
                Enabled = true,
                Realm = new Uri(realm),
                Name = "InMemory realm.",
                SymmetricSigningKey = Convert.FromBase64String("L6aMge6UHG5IJ+Ah10Nhw9wsmkWC9ZBUEHT2lciAwSw=")
            };

            return true;
        }
Esempio n. 3
0
        public async Task <string> GetAuthorizationToken()
        {
            var discoveryClient   = new DiscoveryClient(IDENTITY_AUTHORITY, IdentityServer.CreateHandler());
            var discoveryResponse = await discoveryClient.GetAsync();

            var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint,
                                              "test_client", "secret", IdentityServer.CreateHandler());
            var tokenResponse = await tokenClient.RequestClientCredentialsAsync(
                "brickweave_api");

            return(tokenResponse.AccessToken);
        }
Esempio n. 4
0
        public static IEnumerable <Client> GetClients(IdentityServer identityServer)
        {
            var scopes = new List <string> {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile
            };

            identityServer.Clients.ForEach(p =>
            {
                if (!scopes.Contains(p.ApiResourceName))
                {
                    scopes.Add(p.ApiResourceName);
                }
            });

            var clients = identityServer.Clients?.Where(p => p.GrantType.ToLower().Equals("implicit")).Select(p => new Client
            {
                ClientId   = p.Id,
                ClientName = p.Name,
                //ClientSecrets = { new Secret(p.Secret.Sha256()) },
                AllowedGrantTypes           = GrantTypes.Implicit,
                RequireConsent              = false,
                RedirectUris                = { p.RedirectUrl },
                PostLogoutRedirectUris      = new string[] { p.LogoutRedirectUrl },
                AllowedCorsOrigins          = new string[] { p.AllowedCorsOrigins },
                AllowedScopes               = scopes,
                AllowOfflineAccess          = true,
                AllowAccessTokensViaBrowser = true,
            });

            var clients1 = identityServer.Clients?.Where(p => p.GrantType.ToLower().Equals("resourceownerpasswordandclientcredentials"))?.Select(p => new Client
            {
                ClientId          = p.Id,
                ClientName        = p.Name,
                ClientSecrets     = { new Secret(p.Secret?.Sha256()) },
                AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                RequireConsent    = false,
                //RedirectUris = { p.RedirectUrl },
                //PostLogoutRedirectUris = new string[] { p.LogoutRedirectUrl },
                AllowedCorsOrigins          = new string[] { p.AllowedCorsOrigins },
                AllowedScopes               = scopes,
                AllowOfflineAccess          = true,
                AllowAccessTokensViaBrowser = true,
            });

            if (clients1.Any())
            {
                var cli = clients.Union(clients1);
                return(cli);
            }
            return(clients);
        }
Esempio n. 5
0
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            // [Important] The order of middleware very important for request and response handle!
            // Don't mad it !!!

            // [SystemConfigs]
            SystemConfigs.Middleware(app, loggerFactory);

            // Migrate Database
            app.DatabaseMigrate();

            // [Response] Information
            ProcessingTimeMiddleware.Middleware(app);
            SystemInfoMiddleware.Middleware(app);

            // [Cros] Policy
            Cros.Middleware(app);

            // [Log] Serilog
            Log.Middleware(app, loggerFactory);

            // [Exception]
            Exception.Middleware(app);

            // [Security] Identity Server
            IdentityServer.Middleware(app);

            // [Document API] Swagger
            Swagger.Middleware(app);

            // [Background Job] Hangfire
            Hangfire.Middleware(app);

            // [Mini Response] WebMarkup
            WebMarkupMin.Middleware(app);

            // [MVC] Keep In Last
            Mvc.Middleware(app);
        }
 public IdentityController(IdentityServer idp)
 {
     _idp = idp;
 }
Esempio n. 7
0
        public static IEnumerable <ApiResource> GetApiResources(IdentityServer identityServer)
        {
            var apis = identityServer.ApiResources?.Select(p => new ApiResource(p.Name, p.DisplayName));

            return(apis);
        }
 public void Add(IdentityServer.Models.RelyingParty relyingParty)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 public void Dispose()
 {
     IdentityServer.Dispose();
     ApiServer.Dispose();
 }