Мил*_*лан 5 azure asp.net-identity asp.net-core identityserver4
请帮助,我正在构建一个带有离子前端的 .NET Core API。我想使用 ASPNET Core Identity 所以我或多或少地遵循了这个例子 https://identityserver4.readthedocs.io/en/release/quickstarts/6_aspnet_identity.html
这是我在 Startup.cs 中的内容
// Adds IdentityServer
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients(Configuration))
.AddAspNetIdentity<ApplicationUser>();
Run Code Online (Sandbox Code Playgroud)
和
app.UseIdentity();
app.UseIdentityServer();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = API_address,
RequireHttpsMetadata = false,
ApiName = "myAPIs"
});
Run Code Online (Sandbox Code Playgroud)
在我的 Config.cs 文件中,我有内存配置
public class Config
{
// scopes define the resources in your system
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
};
}
// scopes define the API resources in your system
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource(
"myAPIs", // Api resource name
"My API Set #1", // Display name
new[] { JwtClaimTypes.Name, JwtClaimTypes.Role }) // Claims to be included in access token
};
}
// client want to access resources (aka scopes)
public static IEnumerable<Client> GetClients(IConfigurationRoot configuration)
{
return new List<Client>
{
new Client
{
ClientId = "myClient",
ClientName = "My Custom Client",
AllowedCorsOrigins = new List<string>
{
"whateverINeedHere"
},
AccessTokenLifetime = 60 * 60 * 24,
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
RequireClientSecret = false,
AccessTokenType = AccessTokenType.Jwt,
AllowedScopes =
{
"myAPIs"
}
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当我在本地测试时,一切正常。我点击了 /connect/token 端点,我得到了一个令牌响应,点击了需要令牌授权的控制器,我的声明就在那里。但是,当我将它部署到 Azure 时,当我想使用令牌(从该环境发出)时,我收到 401 Unauthorized 响应标头 invalid_token “发行者无效”。我在谷歌上搜索过,但人们得到的是带有签名问题的无效令牌,而不是发行者。我以前从未使用过身份服务器,对我来说这看起来像是一些配置问题。我已经比较了我从 jwt.io 上的身份服务器获得的令牌,它们看起来完全一样,唯一的区别是发行者 localhost -> myAPIAddress。
有人可以指出我正确的方向吗?
可能是客户端和 IdentityServer 之间存在 SSL/TLS 问题,您是否能够查看 IdentityServer 本身记录的异常?您可能会看到类似以下内容:
"... Could not establish trust relationship for the SSL/TLS..."
Run Code Online (Sandbox Code Playgroud)
如果您在 HTTPS 上运行 IdentityServer,您需要确保您的证书中包含其域/子域。
无论哪种方式,IdentityServer 都会记录大量有用的信息,因此打开日志记录并查看它的内容,这应该会为您指明正确的方向。
| 归档时间: |
|
| 查看次数: |
5843 次 |
| 最近记录: |