This commit is contained in:
2023-05-14 18:55:19 -05:00
parent 257504fa72
commit 809ca92c8a
13 changed files with 130 additions and 24 deletions

View File

@@ -10,7 +10,6 @@ public class AccountManager
{
private readonly AccountState accountState;
private readonly IShogiApi shogiApi;
private readonly IConfiguration configuration;
private readonly ILocalStorage localStorage;
private readonly AuthenticationStateProvider authState;
private readonly NavigationManager navigation;
@@ -19,7 +18,6 @@ public class AccountManager
public AccountManager(
AccountState accountState,
IShogiApi unauthenticatedClient,
IConfiguration configuration,
AuthenticationStateProvider authState,
ILocalStorage localStorage,
NavigationManager navigation,
@@ -27,15 +25,12 @@ public class AccountManager
{
this.accountState = accountState;
this.shogiApi = unauthenticatedClient;
this.configuration = configuration;
this.authState = authState;
this.localStorage = localStorage;
this.navigation = navigation;
this.shogiSocket = shogiSocket;
}
private User? MyUser => accountState.User;
private Task SetUser(User user) => accountState.SetUser(user);

View File

@@ -3,19 +3,21 @@ using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
namespace Shogi.UI.Pages.Home.Api
{
public class MsalMessageHandler : AuthorizationMessageHandler
{
public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation)
{
ConfigureHandler(
authorizedUrls: new[] { "https://api.lucaserver.space", "https://localhost:5001" },
scopes: new[] { "api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope" },
returnUrl: "https://localhost:3000");
}
public class MsalMessageHandler : AuthorizationMessageHandler
{
public MsalMessageHandler(IAccessTokenProvider provider, NavigationManager navigation) : base(provider, navigation)
{
ConfigureHandler(
authorizedUrls: new[] { "https://api.lucaserver.space/Shogi.Api", "https://localhost:5001" },
scopes: new string[] {
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope",
"offline_access",
});
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken);
}
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken);
}
}
}

View File

@@ -3,7 +3,11 @@
<div class="pageHeader">
<h1>Shogi</h1>
@if (user != null)
@if (user == null)
{
<button type="button" class="logout" @onclick="AccountManager.LogoutAsync">Logout</button>
}
else
{
<div class="user">
<div>@user.Value.DisplayName</div>

View File

@@ -39,7 +39,12 @@ static void ConfigureDependencies(IServiceCollection services, IConfiguration co
services.AddMsalAuthentication(options =>
{
configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
options.ProviderOptions.LoginMode = "redirect";
//options.ProviderOptions.DefaultAccessTokenScopes.Add("https://graph.microsoft.com/User.Read");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("openid");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("offline_access");
//options.ProviderOptions.DefaultAccessTokenScopes.Add("profile");
//options.ProviderOptions.LoginMode = "redirect";
});
services.AddOidcAuthentication(options =>
{

View File

@@ -5,11 +5,10 @@
}
},
"AzureAd": {
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
"Authority": "https://login.microsoftonline.com/common",
"ClientId": "935df672-efa6-45fa-b2e8-b76dfd65a122",
"ValidateAuthority": true,
"Scopes": [
"profile",
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope"
]
},