Skip to content

Commit 7454aa6

Browse files
committed
Added .ConfigureAwait(false) to async authentication methods
1 parent fe0c1a7 commit 7454aa6

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

src/DragonFly.ApiKeys/Handlers/ApiKeyAuthenticationHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
3333

3434
if (requestApiKey != null)
3535
{
36-
ApiKey? apiKey = await ApiKeyService.GetApiKey(requestApiKey);
36+
ApiKey? apiKey = await ApiKeyService.GetApiKey(requestApiKey).ConfigureAwait(false);
3737

3838
if (apiKey != null)
3939
{

src/DragonFly.AspNetCore/Permissions/AuthorizationExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static async Task<Result> AuthorizeAsync(this IAuthorizationService autho
2222
return Result.Ok();
2323
}
2424

25-
AuthorizationResult result = await authorizationService.AuthorizeAsync(principal, permission.ToAuthorizationPolicy());
25+
AuthorizationResult result = await authorizationService.AuthorizeAsync(principal, permission.ToAuthorizationPolicy()).ConfigureAwait(false);
2626

2727
if (result.Succeeded)
2828
{

src/DragonFly.Identity/Services/LoginService.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
// https://github.com/usercode/DragonFly
33
// MIT License
44

5-
using DragonFly.AspNetCore;
6-
using DragonFly.AspNetCore.Identity.MongoDB;
75
using DragonFly.AspNetCore.Identity.MongoDB.Models;
86
using DragonFly.AspNetCore.Identity.MongoDB.Services.Base;
97
using DragonFly.AspNetCore.Identity.MongoDB.Storages.Models;
108
using DragonFly.Identity.Services;
119
using DragonFly.Security;
1210
using Microsoft.AspNetCore.Authentication;
13-
using Microsoft.AspNetCore.Components.Authorization;
14-
using Microsoft.AspNetCore.Components.Server;
1511
using Microsoft.AspNetCore.Http;
1612
using MongoDB.Driver;
1713
using MongoDB.Driver.Linq;
@@ -55,7 +51,7 @@ public LoginService(
5551

5652
public async Task<LoginResult> LoginAsync(string username, string password, bool isPersistent)
5753
{
58-
MongoIdentityUser? user = await Store.Users.AsQueryable().FirstOrDefaultAsync(x => x.Username == username);
54+
MongoIdentityUser? user = await Store.Users.AsQueryable().FirstOrDefaultAsync(x => x.Username == username).ConfigureAwait(false);
5955

6056
if (user == null)
6157
{
@@ -81,7 +77,7 @@ public async Task<LoginResult> LoginAsync(string username, string password, bool
8177

8278
PrincipalContext.Current = principal;
8379

84-
await HttpContextAccessor.HttpContext!.SignInAsync(IdentityAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties() { IsPersistent = isPersistent });
80+
await HttpContextAccessor.HttpContext!.SignInAsync(IdentityAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties() { IsPersistent = isPersistent }).ConfigureAwait(false);
8581

8682
return new LoginResult(true) { Username = user.Username, Claims = claims.Select(x=> new ClaimItem(x.Type, x.Value)).ToList() };
8783
}
@@ -101,7 +97,7 @@ public async Task Logout()
10197
{
10298
Guid userIdGuid = Guid.Parse(claimUserId);
10399

104-
MongoIdentityUser? currentUser = await Store.Users.AsQueryable().FirstOrDefaultAsync(x => x.Id == userIdGuid);
100+
MongoIdentityUser? currentUser = await Store.Users.AsQueryable().FirstOrDefaultAsync(x => x.Id == userIdGuid).ConfigureAwait(false);
105101

106102
if (currentUser != null)
107103
{

src/DragonFly.Identity/Services/PermissionHandler.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
4545
}
4646

4747
Guid userId = Guid.Parse(claim.Value);
48-
MongoIdentityUser user = await Store.Users.AsQueryable().FirstAsync(x => x.Id == userId);
48+
MongoIdentityUser user = await Store.Users.AsQueryable().FirstAsync(x => x.Id == userId).ConfigureAwait(false);
4949

5050
string[] permissions = Api.Permission().Get(requirement.Permission);
5151

5252
bool found = await Store.Roles.AsQueryable()
5353
.Where(x => user.Roles.Contains(x.Id))
5454
.Where(x => permissions.Any(p => x.Permissions.Contains(p)))
55-
.AnyAsync();
55+
.AnyAsync()
56+
.ConfigureAwait(false);
5657

5758
if (found)
5859
{

0 commit comments

Comments
 (0)