C# OWIN-在后续请求中访问外部声明

C# OWIN-在后续请求中访问外部声明,c#,asp.net,oauth,oauth-2.0,owin,C#,Asp.net,Oauth,Oauth 2.0,Owin,我有一个ASP.Net应用程序,它使用OWIN和通过第三方提供商(特别是google)的外部登录 在身份验证期间,此代码用于从文本中提取ClaimsIdentity var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); AuthenticationManager在哪里 private IAuthenticationManager AuthenticationManager {

我有一个ASP.Net应用程序,它使用OWIN和通过第三方提供商(特别是google)的外部登录

在身份验证期间,此代码用于从文本中提取ClaimsIdentity

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
AuthenticationManager在哪里

    private IAuthenticationManager AuthenticationManager
    {
        get
        {
            return HttpContext.GetOwinContext().Authentication;
        }
    }
但是,在后续请求中(即成功登录后重定向到主页),getExternalLoginFoAsync()返回null。我想做的是访问外部提供者从我的身份验证请求返回的有关用户帐户(即配置文件图片)的信息。如何从MVC控制器或Web API控制器访问这些声明

我拥有的几乎所有代码都是VisualStudio锅炉板代码,所以我不会在这里包含它,但是如果需要任何特定的代码,我可以添加一些


感谢您提供的任何帮助。

我试图使用外部登录信息来获取图片和个人资料url等数据。正确的方法是将外部来源的索赔分配给本地标识,以便:

  public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager, IAuthenticationManager authentication = null)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here

        if (authentication != null)
        {
            ExternalLoginInfo info = authentication.GetExternalLoginInfo();

            if (info != null)
                foreach (Claim claim in info.ExternalIdentity.Claims.Where(claim => !userIdentity.HasClaim(c => c.Type == claim.Type)))
                {
                    userIdentity.AddClaim(claim);
                    await manager.AddClaimAsync(userIdentity.GetUserId(), claim);
                }
        }

        return userIdentity;
    }
公共异步任务GenerateUserIdentityAsync(UserManager管理器,IAAuthenticationManager身份验证=null)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
if(身份验证!=null)
{
ExternalLoginInfo info=authentication.GetExternalLoginInfo();
如果(信息!=null)
foreach(在info.ExternalIdentity.Claims.Where(Claim=>!userIdentity.HasClaim(c=>c.Type==Claim.Type))中声明)
{
userIdentity.AddClaim(索赔);
wait manager.addClaudisync(userIdentity.GetUserId(),claim);
}
}
返回用户身份;
}

我试图使用外部登录信息来提取图片和个人资料url等数据。正确的方法是将外部来源的索赔分配给本地标识,以便:

  public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager, IAuthenticationManager authentication = null)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here

        if (authentication != null)
        {
            ExternalLoginInfo info = authentication.GetExternalLoginInfo();

            if (info != null)
                foreach (Claim claim in info.ExternalIdentity.Claims.Where(claim => !userIdentity.HasClaim(c => c.Type == claim.Type)))
                {
                    userIdentity.AddClaim(claim);
                    await manager.AddClaimAsync(userIdentity.GetUserId(), claim);
                }
        }

        return userIdentity;
    }
公共异步任务GenerateUserIdentityAsync(UserManager管理器,IAAuthenticationManager身份验证=null)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
if(身份验证!=null)
{
ExternalLoginInfo info=authentication.GetExternalLoginInfo();
如果(信息!=null)
foreach(在info.ExternalIdentity.Claims.Where(Claim=>!userIdentity.HasClaim(c=>c.Type==Claim.Type))中声明)
{
userIdentity.AddClaim(索赔);
wait manager.addClaudisync(userIdentity.GetUserId(),claim);
}
}
返回用户身份;
}