ASP.netコア2.0を使用している間、私はUserManager
によってCurrentUser
を取得しようとしました。この
public ClaimsIdentity GenerateClaimsIdentity(string email, string id)
{
return new ClaimsIdentity(new GenericIdentity(email, "Token"), new[]
{
new Claim(Helpers.Constants.Strings.JwtClaimIdentifiers.Id, id),
new Claim(Helpers.Constants.Strings.JwtClaimIdentifiers.Rol, Helpers.Constants.Strings.JwtClaims.ApiAccess)
});
}
などのJWTトークンを生成するので、私は同じ問題に直面してきましたが、それは常にnull
を返します。このようなスタートアップファイルのUserIdClaimType
文字列を "id"に変更すると考えました
var builder = services.AddIdentity<User,IdentityRole>(o =>
{
// configure identity options
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
//this line
o.ClaimsIdentity.UserIdClaimType = "id";
});
このアプリケーションではどのような認証メカニズムが使用されていますか? ClaimsPrincipalを作成したのは何ですか? .NET Core 2.0ですか? –
はい、.NET Core 2.0です。私は認証のためにJwtBearerを使用しています。私はClaimsPrincipleに精通していないので、JwtBearerがそれを処理していると思いますか? –
申し訳ありませんが、私は認証のためのアイデンティティ(jwtトークン用のJwtBeaerを使用しています) –