【发布时间】:2021-05-11 00:04:42
【问题描述】:
我目前有一个带有 Blazor WASM 的 ASP.Net Core Web Api,它可以使用组件 RemoteAuthenticatorView 成功登录到 Google OAuth。我现在的意图是将我拥有的令牌传递给 web api,希望它可以用来对 web api 进行身份验证。问题是 TokenProvider.RequestAccessToken() 产生以下错误。
blazor.webassembly.js:1 Microsoft.JSInterop.JSException: An exception occurred executing JS interop: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 88.. See InnerException for more details.
System.Text.Json.JsonException: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 88.
var tokenResult = await TokenProvider.RequestAccessToken();
if (tokenResult.TryGetToken(out var token))
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", token.Value);
var response = await Http.SendAsync(requestMessage);
}
程序.cs
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("Local", options.ProviderOptions);
options.ProviderOptions.DefaultScopes.Add("email");
});
有什么想法吗?是否缺少范围?我可以在 Session 存储中看到 id_token...也许有任何 Blazor WASM 和核心 web api 的 net 5 示例?
编辑: 我看到 RequestAccessToken 对 google auth 进行了网络调用,就像它试图再次进行身份验证一样
【问题讨论】:
-
能否请您发布驻留在客户端项目的 wwwroot 文件夹中的 appsettings.json 文件的内容。
-
{"Authority": "accounts.google.com", "ClientId": "3XXXXo1gn4loba5om5b4.apps.googleusercontent.com", "PostLogoutRedirectUri": "localhost:44313/authentication/logout-callback", "RedirectUri": "@987654323 @", "ResponseType": "id_token"}
标签: asp.net-core-webapi blazor blazor-client-side