2016-12-22 19 views
0

私はMVCアプリケーションの認証サーバーとしてIdentityserver3を使用しています。したがって、私のStartupクラスは、このようなものです:提供されたClaimsIdentityに '.../nameidentifier'が存在しません

public void Configuration(IAppBuilder app) 
{ 

    app.UseExternalSignInCookie(); 
    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationType = "Cookies" 
    }); 
    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
    { 
     Authority = "http://localhost:5000/", 
     ClientId = "mvc", 
     RedirectUri = "http://localhost:12262/", 
     ResponseType = "id_token", 
     UseTokenLifetime = false, 
     SignInAsAuthenticationType = "Cookies" 
    }); 
} 

これは私のIdentityUserサブクラスです:

public class ApplicationUser : IdentityUser 
{ 
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) 
    { 

     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
     userIdentity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", this.Email)); 
     userIdentity.AddClaim(
      new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", 
       this.Email)); 

     return userIdentity; 
    } 

    public UserType UserType { get; set; } 
    .... 
} 

これは私のGlobal.asax.csです:

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 

    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    RouteConfig.RegisterRoutes(RouteTable.Routes); 
    BundleConfig.RegisterBundles(BundleTable.Bundles); 

    AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; 
} 

しかし含む行で私のAccount/Registerビューで@Html.AntiForgeryToken()このエラーが表示されます:

タイプ

' http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier ' was not present on the provided ClaimsIdentity.

の主張は、私は(多分どこでもIdentityserver3を使用していない)同様の問題を持つSO上のいくつかの質問を見てきましたが、その解決策は、私はそれらを使用していた少なくとも方法、動作しないようです。

答えて

0

IMHO私は問題が適切な場所に追加されていないと考えています。しかし、これを確認するには私はいくつかのフィードバックが必要です。 Identity Serverに関連してMicrosoft.AspNet.Identity *(NuGetパッケージ)を使用していますか? コードでユーザーを作成するのか、データベースからユーザーを作成していますか?例えば

私はあなたがfolllowingのようなユーザーサービスGetClaimsFromAccount方法を変更することができ、各ユーザーのクレームを追加するIdentityServer3とAspNet.Identityを使用して:identityServer3.coreを含む定数が付属していることを

using System.Collections.Generic; 
using System.Data.Entity; 
using System.Linq; 
using System.Threading.Tasks; 
using IdentityServer3.Core; 
using IdentityServer3.AspNetIdentity; 
using IdentityServer3.Core.Configuration; 
using IdentityServer3.Core.Services; 

namespace ..... { 

public class UserService : AspNetIdentityUserService<IdentityUser, string> 
{ 
    public UserService(UserManager userMgr) : base(userMgr) 
    { 
    } 

    protected override async Task<IEnumerable<System.Security.Claims.Claim>> GetClaimsFromAccount(IdentityUser user) 
    { 
     var claims = (await base.GetClaimsFromAccount(user)).ToList(); 

     // to make sure the email is in the claims 
     if (claims.Any(c=>c.Type == Constants.ClaimTypes.Email) && !string.IsNullOrWhiteSpace(user.Email)) 
     { 
      claims.Add(.....); 
     } 

     return claims; 
    } 
} 
.... 
} 

お知らせクレームタイプ(Constants.Claimtypes.Email)。

ほんの少し役に立ちます:)

関連する問題