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/ProfileService.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/server/IdentityServer/ProfileService.cs') 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