【发布时间】:2021-09-10 08:11:12
【问题描述】:
我正在尝试在具有身份服务器 4 个个人帐户的 blazor webassembly asp.net 核心托管应用程序中使用邮递员测试我的 api。不幸的是,尽管尝试了许多不同的配置选项来获取新令牌,但我一直无法获得。这是我尝试过的
这会导致邮递员浏览器模拟器弹出并且永远不会完成。
这个失败了,但我得到了比info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2] Authorization failed. These requirements were not met: DenyAnonymousAuthorizationRequirement: Requires an authenticated user.更多信息的错误
但是,当我尝试使用默认的测试用户名和密码时,我得到Error: unauthorized_client
我在this article 中使用API authorization options 而不是配置文件服务选项逐步按照设置进行操作(并且我正在本地开发,而不是使用azure。)我需要做什么才能获得令牌?感谢您的帮助,谢谢。
编辑:尝试在 ConfigureServices 中添加一个新客户端,但同样的行为发生在邮递员浏览器模拟器弹出并且永远不会完成。
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(options => {
options.IdentityResources["openid"].UserClaims.Add("name");
options.ApiResources.Single().UserClaims.Add("name");
options.IdentityResources["openid"].UserClaims.Add("role");
options.ApiResources.Single().UserClaims.Add("role");
options.Clients.Add(new IdentityServer4.Models.Client()
{
ClientId = "postman",
AllowedGrantTypes = GrantTypes.Code,
AllowOfflineAccess = true,
ClientSecrets = { new Secret("secret".Sha256()) },
RedirectUris = { "http://localhost:21402/signin-oidc", "https://oauth.pstmn.io/v1/browser-callback" },
PostLogoutRedirectUris = { "http://localhost:21402/" },
FrontChannelLogoutUri = "http://localhost:21402/signout-oidc",
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"Onero.ServerAPI"
},
});
});
【问题讨论】:
-
尝试使用
https://oauth.pstmn.io/v1/browser-callback作为回调 URL。您可能需要将此添加到 IdentityServer 中允许的重定向 URL -
您收到
unauthorized_client错误的原因是客户端无权使用密码凭据授予。即使您允许,您也必须实现IResourceOwnerPasswordValidator来验证用户凭据
标签: asp.net-core oauth-2.0 jwt postman identityserver4