-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAS-554 | Fix Access Denied creating application in different session…
…/window. (#672)
- Loading branch information
1 parent
dda0071
commit 4d08754
Showing
3 changed files
with
23 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 3 additions & 18 deletions
21
src/AdminConsole/Services/CustomUserClaimsPrincipalFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
using System.Security.Claims; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Options; | ||
using Passwordless.AdminConsole.Db; | ||
using Passwordless.AdminConsole.Authorization; | ||
using Passwordless.AdminConsole.Identity; | ||
|
||
namespace Passwordless.AdminConsole.Services; | ||
|
||
public class CustomUserClaimsPrincipalFactory : UserClaimsPrincipalFactory<ConsoleAdmin> | ||
{ | ||
private readonly ConsoleDbContext _db; | ||
|
||
public CustomUserClaimsPrincipalFactory( | ||
UserManager<ConsoleAdmin> userManager, | ||
IOptions<IdentityOptions> optionsAccessor, | ||
ConsoleDbContext db | ||
IOptions<IdentityOptions> optionsAccessor | ||
) | ||
: base(userManager, optionsAccessor) | ||
{ | ||
_db = db; | ||
} | ||
|
||
protected override async Task<ClaimsIdentity> GenerateClaimsAsync(ConsoleAdmin user) | ||
{ | ||
ClaimsIdentity identity = await base.GenerateClaimsAsync(user); | ||
identity.AddClaim(new Claim("OrgId", user.OrganizationId.ToString())); | ||
|
||
// add apps | ||
List<string> apps = await _db.Applications.Where(a => a.OrganizationId == user.OrganizationId) | ||
.Select(a => a.Id).ToListAsync(); | ||
|
||
foreach (var appId in apps) | ||
{ | ||
identity.AddClaim(new Claim("AppId", appId)); | ||
} | ||
|
||
identity.AddClaim(new Claim(CustomClaimTypes.OrgId, user.OrganizationId.ToString())); | ||
return identity; | ||
} | ||
} |