Skip to content

Commit

Permalink
Make GetUserClaims and GetManagementClaims Async
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannikolei committed Aug 20, 2023
1 parent 0b88db5 commit 1af7f31
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Duende.Bff/EndpointServices/User/DefaultUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -71,8 +72,8 @@ public virtual async Task ProcessRequestAsync(HttpContext context)
else
{
var claims = new List<ClaimRecord>();
claims.AddRange(GetUserClaims(result));
claims.AddRange(GetManagementClaims(context, result));
claims.AddRange(await GetUserClaimsAsync(result));
claims.AddRange(await GetManagementClaimsAsync(context, result));

var json = JsonSerializer.Serialize(claims);

Expand All @@ -89,9 +90,9 @@ public virtual async Task ProcessRequestAsync(HttpContext context)
/// </summary>
/// <param name="authenticateResult"></param>
/// <returns></returns>
protected virtual IEnumerable<ClaimRecord> GetUserClaims(AuthenticateResult authenticateResult)
protected virtual ValueTask<IEnumerable<ClaimRecord>> GetUserClaimsAsync(AuthenticateResult authenticateResult)
{
return authenticateResult.Principal?.Claims.Select(x => new ClaimRecord(x.Type, x.Value)) ?? Enumerable.Empty<ClaimRecord>();
return ValueTask.FromResult(authenticateResult.Principal?.Claims.Select(x => new ClaimRecord(x.Type, x.Value)) ?? Enumerable.Empty<ClaimRecord>());
}

/// <summary>
Expand All @@ -100,7 +101,7 @@ protected virtual IEnumerable<ClaimRecord> GetUserClaims(AuthenticateResult auth
/// <param name="context"></param>
/// <param name="authenticateResult"></param>
/// <returns></returns>
protected virtual IEnumerable<ClaimRecord> GetManagementClaims(HttpContext context, AuthenticateResult authenticateResult)
protected virtual ValueTask<IEnumerable<ClaimRecord>> GetManagementClaimsAsync(HttpContext context, AuthenticateResult authenticateResult)
{
var claims = new List<ClaimRecord>();

Expand Down Expand Up @@ -131,7 +132,7 @@ protected virtual IEnumerable<ClaimRecord> GetManagementClaims(HttpContext conte
}
}

return claims;
return ValueTask.FromResult(claims as IEnumerable<ClaimRecord>);
}

/// <summary>
Expand Down

0 comments on commit 1af7f31

Please sign in to comment.