ヘルプ、私はイオンフロントエンドで.NET Core APIを構築しています。私は、私は多かれ少なかれ、この例で、次のここ https://identityserver4.readthedocs.io/en/release/quickstarts/6_aspnet_identity.htmlIdentityServer4 invalid_token Azureで「発行者が無効です」、ローカルホストで対応
は私がStartup.cs
// Adds IdentityServer
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients(Configuration))
.AddAspNetIdentity<ApplicationUser>();
と
app.UseIdentity();
app.UseIdentityServer();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = API_address,
RequireHttpsMetadata = false,
ApiName = "myAPIs"
});
、私のConfigでに持っているものであるたASPNETコアアイデンティティを使用したいですメモリ構成の.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"
}
}
};
}
}
問題は、これをローカルでテストするとすべてうまく動作するということです。 私は/ connect/tokenエンドポイントに到達しました。私はトークンレスポンスを取得し、トークン認可を必要とするコントローラにヒットし、私のクレームはそこにあります。しかし、Azureにデプロイするときに、その環境から発行されたトークンを使用したい場合、私は401ヘッダーのinvalid_tokenを "Unsuhorized"とします。 "発行者は無効です"私はグーグルではありますが、発行者ではなく署名の問題で無効なトークンを取得します。以前はアイデンティティ・サーバーを使ったことが一度もありませんでしたが、これは構成上の問題のようです。私はjwt.ioのアイデンティティサーバーから得たトークンを比較しました。それらはまったく同じように見えますが、唯一の違いは発行者のlocalhost - > myAPIAddressです。
誰かが正しい方向に向かうことができますか?
こんにちはマット、あなたの答えをありがとう。はい、私はHTTPS上ですべてを実行しており、私はここで指示に従って設定しています(Serilogの代わりにLogglyを使用しています) {"IdentityServer"、LogLevel.Debug} IdentityServerからデバッグ情報は表示されませんでした。私のコードから他のデバッグ情報が表示されます。 –
OK、IdentityServerが実行されているドメインまたはサブドメインは、証明書の共通名または代替名ですか? – Matt