Skip to content

Commit

Permalink
added await configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Faruk Redzic committed Jul 1, 2021
1 parent 685041a commit 45c6967
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 8 additions & 7 deletions Klika.AuthApi.Service/User/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public async Task<IdentityResult> Register(ApplicationUserDTO user)
try
{
ApplicationUser applicationUser = _mapper.Map<ApplicationUserDTO, ApplicationUser>(user);
var identityResult = await _userManager.CreateAsync(applicationUser, user.Password);
var identityResult = await _userManager.CreateAsync(applicationUser, user.Password).ConfigureAwait(false);

if (identityResult.Succeeded)
{
await _userManager.AddClaimsAsync(applicationUser, new List<Claim>() {
new Claim("email", applicationUser.Email)
});
await _userManager.AddToRolesAsync(applicationUser, new List<string>() { "admin" }); // Define user roles on registration
}).ConfigureAwait(false);
await _userManager.AddToRolesAsync(applicationUser, new List<string>() { "admin" })
.ConfigureAwait(false); // Define user roles on registration
}

return identityResult;
Expand Down Expand Up @@ -81,7 +82,7 @@ public async Task<TokenResponse> Token(TokenRequestDTO tokenRequest)
Scope = tokenRequest.Scope,
UserName = tokenRequest.Username,
Password = tokenRequest.Password
});
}).ConfigureAwait(false);
return passwordFlow;
case "client_credentials":
var clientCredentialsFlow = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest()
Expand All @@ -90,7 +91,7 @@ public async Task<TokenResponse> Token(TokenRequestDTO tokenRequest)
ClientId = tokenRequest.ClientId,
ClientSecret = tokenRequest.ClientSecret,
Scope = tokenRequest.Scope,
});
}).ConfigureAwait(false);
return clientCredentialsFlow;
default:
throw new Exception("grant_type is not supported");
Expand Down Expand Up @@ -121,7 +122,7 @@ public async Task<TokenResponse> RefreshToken(TokenRequestDTO tokenRequest)
ClientId = tokenRequest.ClientId,
ClientSecret = tokenRequest.ClientSecret,
RefreshToken = tokenRequest.RefreshToken
});
}).ConfigureAwait(false);
return refreshToken;
}
catch (Exception ex)
Expand All @@ -148,7 +149,7 @@ public async Task<TokenRevocationResponse> RevokeToken(TokenRequestDTO tokenRequ
ClientId = tokenRequest.ClientId,
ClientSecret = tokenRequest.ClientSecret,
Token = tokenRequest.RefreshToken
});
}).ConfigureAwait(false);
return revokeResult;
}
catch (Exception ex)
Expand Down
12 changes: 8 additions & 4 deletions Klika.AuthApi/Controllers/IdentityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public async Task<ActionResult<IdentityResult>> Register([FromBody] ApplicationU
{
try
{
IdentityResult result = await _userService.Register(user);
IdentityResult result = await _userService.Register(user)
.ConfigureAwait(false);

if (result.Succeeded)
return Ok(result);
Expand All @@ -52,7 +53,8 @@ public async Task<IActionResult> Token([FromBody] TokenRequestDTO tokenRequest)
{
try
{
TokenResponse result = await _userService.Token(tokenRequest);
TokenResponse result = await _userService.Token(tokenRequest)
.ConfigureAwait(false);
if (!result.IsError)
return Ok(result.Json);
return Conflict(result.Json);
Expand All @@ -70,7 +72,8 @@ public async Task<IActionResult> RefreshToken([FromBody] TokenRequestDTO tokenRe
{
try
{
TokenResponse result = await _userService.RefreshToken(tokenRequest);
TokenResponse result = await _userService.RefreshToken(tokenRequest)
.ConfigureAwait(false);
if (!result.IsError)
return Ok(result.Json);
return Conflict(result.Json);
Expand All @@ -88,7 +91,8 @@ public async Task<ActionResult<TokenRevocationResponse>> RevokeToken([FromBody]
{
try
{
TokenRevocationResponse result = await _userService.RevokeToken(tokenRequest);
TokenRevocationResponse result = await _userService.RevokeToken(tokenRequest)
.ConfigureAwait(false);
if (!result.IsError)
return Ok();
return Conflict(result.Json);
Expand Down

0 comments on commit 45c6967

Please sign in to comment.