-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: Fix BlazorCurrentPrincipalAccessor in BlazorWebAssembly
- Loading branch information
Showing
8 changed files
with
70 additions
and
7 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
9 changes: 9 additions & 0 deletions
9
...Authentication.Identity.BlazorWebAssembly/ComponentsClientScopeServiceProviderAccessor.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.Identity.BlazorWebAssembly; | ||
|
||
public class ComponentsClientScopeServiceProviderAccessor : IClientScopeServiceProviderAccessor | ||
{ | ||
public IServiceProvider ServiceProvider { get; set; } | ||
} |
32 changes: 32 additions & 0 deletions
32
...ntity/Masa.Contrib.Authentication.Identity.BlazorWebAssembly/MasaComponentsClaimsCache.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.Identity.BlazorWebAssembly; | ||
|
||
public class MasaComponentsClaimsCache : IScopedDependency | ||
{ | ||
public ClaimsPrincipal Principal { get; private set; } | ||
private readonly AuthenticationStateProvider _authenticationStateProvider; | ||
|
||
public MasaComponentsClaimsCache( | ||
IClientScopeServiceProviderAccessor serviceProviderAccessor) | ||
{ | ||
_authenticationStateProvider = serviceProviderAccessor.ServiceProvider.GetService<AuthenticationStateProvider>(); | ||
if (_authenticationStateProvider != null) | ||
{ | ||
_authenticationStateProvider.AuthenticationStateChanged += async (task) => | ||
{ | ||
Principal = (await task).User; | ||
}; | ||
} | ||
} | ||
|
||
public virtual async Task InitializeAsync() | ||
{ | ||
if (_authenticationStateProvider != null) | ||
{ | ||
var authenticationState = await _authenticationStateProvider.GetAuthenticationStateAsync(); | ||
Principal = authenticationState.User; | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...Identity/Masa.Contrib.Authentication.Identity.Core/IClientScopeServiceProviderAccessor.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.Identity.Core; | ||
|
||
public interface IClientScopeServiceProviderAccessor | ||
{ | ||
IServiceProvider ServiceProvider { get; } | ||
} |
2 changes: 1 addition & 1 deletion
2
...ntication/Identity/Masa.Contrib.Authentication.Identity.Core/ICurrentPrincipalAccessor.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
2 changes: 1 addition & 1 deletion
2
...entity/Tests/Masa.Contrib.Authentication.Identity.BlazorWebAssembly.Tests/IdentityTest.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