Skip to content

Commit 0b57efb

Browse files
committed
refactor: audition check as async allowing non-static checks
1 parent 49e53f2 commit 0b57efb

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/ProductizerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public async Task<IActionResult> SaveOrUpdatePersonJobApplicantProfile(UpdateJob
159159
e.Message);
160160
try
161161
{
162-
var jwkToken = _authenticationService.ParseAuthenticationHeader(Request);
162+
var jwkToken = await _authenticationService.ParseAuthenticationHeader(Request);
163163
var query = new VerifyIdentityUser.Query(jwkToken.UserId, jwkToken.Issuer);
164164
var createdUser = await _mediator.Send(query);
165165
userId = createdUser.Id;

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Helpers/Services/AuthenticationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AuthenticationService(UserSecurityService userSecurityService)
1818
return person.Id;
1919
}
2020

21-
public JwtTokenResult ParseAuthenticationHeader(HttpRequest httpRequest)
21+
public Task<JwtTokenResult> ParseAuthenticationHeader(HttpRequest httpRequest)
2222
{
2323
var token = httpRequest.Headers.Authorization.ToString().Replace("Bearer ", string.Empty);
2424
return _userSecurityService.ParseJwtToken(token);

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Helpers/Services/UserSecurityService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public UserSecurityService(UsersDbContext usersDbContext, ILogger<UserSecuritySe
2727
/// <exception cref="NotAuthorizedException">If user id and the issuer are not found in the DB for any given user, this is not a valid user within the users database.</exception>
2828
public async Task<Person> VerifyAndGetAuthenticatedUser(string token)
2929
{
30-
var jwtTokenResult = ParseJwtToken(token);
30+
var jwtTokenResult = await ParseJwtToken(token);
3131

3232
try
3333
{
@@ -44,7 +44,7 @@ public async Task<Person> VerifyAndGetAuthenticatedUser(string token)
4444
/// <summary>
4545
/// Parses the JWT token and returns the issuer and the user id
4646
/// </summary>
47-
public JwtTokenResult ParseJwtToken(string token)
47+
public Task<JwtTokenResult> ParseJwtToken(string token)
4848
{
4949
return _applicationSecurity.ParseJwtToken(token);
5050
}

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Security/ApplicationSecurity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ApplicationSecurity(List<ISecurityFeature> features)
1717
/// <summary>
1818
/// Parses the JWT token and returns the issuer and the user id
1919
/// </summary>
20-
public JwtTokenResult ParseJwtToken(string token)
20+
public async Task<JwtTokenResult> ParseJwtToken(string token)
2121
{
2222
if (string.IsNullOrEmpty(token)) throw new NotAuthorizedException("No token provided");
2323

@@ -32,7 +32,7 @@ public JwtTokenResult ParseJwtToken(string token)
3232

3333
// Resolve and validate the token audience
3434
var tokenAudience = parsedToken.Audiences.FirstOrDefault() ?? throw new NotAuthorizedException("The given token audience is not valid");
35-
securityFeature.ValidateSecurityTokenAudience(tokenAudience);
35+
await securityFeature.ValidateSecurityTokenAudience(tokenAudience);
3636

3737
// Resolve user id
3838
var userId = securityFeature.ResolveTokenUserId(parsedToken) ?? throw new NotAuthorizedException("The given token claim is not valid");

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Security/Features/ISecurityFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface ISecurityFeature
1010
void BuildAuthorization(AuthorizationOptions options);
1111
string GetSecurityPolicySchemeName();
1212
string? ResolveTokenUserId(JwtSecurityToken jwtSecurityToken);
13-
void ValidateSecurityTokenAudience(string audience);
13+
Task ValidateSecurityTokenAudience(string audience);
1414

1515
public string Issuer { get; }
1616
}

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Security/IApplicationSecurity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace VirtualFinland.UserAPI.Security.Models;
22

33
public interface IApplicationSecurity
44
{
5-
JwtTokenResult ParseJwtToken(string token);
5+
Task<JwtTokenResult> ParseJwtToken(string token);
66
}

0 commit comments

Comments
 (0)