From a5f1018fda5572912c126b1e8dd656209fca0e46 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Tue, 11 Aug 2020 21:16:02 +0200 Subject: persisted grants --- src/server/IdentityServer/Config.cs | 7 +------ src/server/IdentityServer/ProfileService.cs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src/server/IdentityServer') diff --git a/src/server/IdentityServer/Config.cs b/src/server/IdentityServer/Config.cs index c005377..ac38aa4 100644 --- a/src/server/IdentityServer/Config.cs +++ b/src/server/IdentityServer/Config.cs @@ -18,20 +18,15 @@ namespace Dough.IdentityServer ClientId = BrowserClientId, AllowedGrantTypes = GrantTypes.Code, RequireClientSecret = false, - RedirectUris = Constants.BrowserAppLoginRedirectUrls, PostLogoutRedirectUris = Constants.BrowserAppLogoutRedirectUrls, AllowedCorsOrigins = Constants.BrowserAppUrls, AccessTokenType = AccessTokenType.Reference, RequireConsent = false, RefreshTokenExpiration = TokenExpiration.Sliding, + RefreshTokenUsage = TokenUsage.ReUse, AlwaysSendClientClaims = true, AllowOfflineAccess = true, - Claims = new List - { - new ClientClaim() - }, - AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, diff --git a/src/server/IdentityServer/ProfileService.cs b/src/server/IdentityServer/ProfileService.cs index 197086c..0c14dd5 100644 --- a/src/server/IdentityServer/ProfileService.cs +++ b/src/server/IdentityServer/ProfileService.cs @@ -1,8 +1,11 @@ -using System.Reflection; +using System; +using System.Collections.Generic; +using System.Security.Claims; using System.Threading.Tasks; +using Dough.Models; using Dough.Models.Database; using Dough.Utilities; -using IdentityServer4; +using IdentityModel; using IdentityServer4.Models; using IdentityServer4.Services; @@ -17,14 +20,24 @@ namespace Dough.IdentityServer _context = context; } - public Task GetProfileDataAsync(ProfileDataRequestContext context) + public async Task GetProfileDataAsync(ProfileDataRequestContext context) { - throw new System.NotImplementedException(); + var userId = context.Subject.GetClaimValueOrDefault(JwtClaimTypes.Subject)?.ToGuidOrDefault(); + if (userId == default) return; + var user = _context.Users.SingleOrDefault((Guid) userId); + var claims = new List + { + new Claim(JwtClaimTypes.PreferredUserName, user.Username) + }; + context.AddRequestedClaims(claims); } - public Task IsActiveAsync(IsActiveContext context) + public async Task IsActiveAsync(IsActiveContext context) { - return default; + var userId = context.Subject.GetClaimValueOrDefault(JwtClaimTypes.Subject)?.ToGuidOrDefault(); + if (userId == default) return; + var user = _context.Users.SingleOrDefault((Guid) userId); + context.IsActive = !user.Hidden; } } } \ No newline at end of file -- cgit v1.3