asp.net-web-api - 可以使用客户端登录,但不能发出 API 请求。401
问题描述
我有引用 IdentityServer3 库的 .Net Framework Web API(旧)
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:5001",
ValidationMode = ValidationMode.Local,
RequiredScopes = new[] { "api1" }
});
身份服务器5:
new Client { ClientId = "mvc",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "https://localhost:5002/signin-oidc" },
PostLogoutRedirectUris = { "https://localhost:5002/signout-callback-oidc" },
AllowedScopes = new List<string> { OpenId, Profile }
}, new Client { ClientId = "client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedScopes = { "api1" }}
有效的网络客户端:
services.AddAuthentication(options =>
{ options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc"; })
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{ options.Authority = "https://localhost:5001";
options.ClientId = "mvc";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.SaveTokens = true; });
但是,当我从客户端调用 API 并将其作为授权承载传递时,它不起作用。我只是无缘无故地得到一个普通的401。我错过了什么。
解决方案
推荐阅读
- conv-neural-network - 在 resnet18 中将输入通道从 3 更改为 1
- angular - 无法以角度读取 null 的属性“valideDate”
- reactjs - 在 Web 应用程序内的 Excel 中编辑/保存和填充图表
- node.js - npm 更新和对等依赖的问题
- vb.net - 如何在 vb .NET 中获得两次之间的持续时间
- php - Netbeans PHP:带有 JSON 主体的 PUT 请求的详细运行配置 - 使用 XDEBUG 需要如此详细的配置
- r - 列出倒数第二个单元格的空值
- python - 使用 neo4j python 驱动程序的简单示例?
- c - 为什么 const 限定变量被接受为 gcc 上的初始化程序?
- c# - 使用 RestClient 从 Google Cloud OAuth 提供程序检索访问令牌