Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net .net web api spa-访问GetUserInfo中的AuthenticationProperties_Asp.net_Asp.net Web Api_Single Page Application_Owin - Fatal编程技术网

Asp.net .net web api spa-访问GetUserInfo中的AuthenticationProperties

Asp.net .net web api spa-访问GetUserInfo中的AuthenticationProperties,asp.net,asp.net-web-api,single-page-application,owin,Asp.net,Asp.net Web Api,Single Page Application,Owin,我创建了一个新的项目使用淘汰温泉VS模板 在AccountController中有一个方法GetExternalLogin,该方法末尾有以下代码: Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); ClaimsIdentity oAuthIdentity=await UserManager.CreateIdentityAsync(用户,OAuthDefaults.AuthenticationType); Clai

我创建了一个新的项目使用淘汰温泉VS模板

AccountController
中有一个方法
GetExternalLogin
,该方法末尾有以下代码:

Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);
ClaimsIdentity oAuthIdentity=await UserManager.CreateIdentityAsync(用户,OAuthDefaults.AuthenticationType);
ClaimSideEntity cookieIdentity=await UserManager.CreateIdentityAsync(用户,CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties=ApplicationAuthProvider.CreateProperties(user.UserName);
身份验证.签名(属性、oAuthIdentity、cookieIdentity);
我修改了方法
CreateProperties
,以返回一些额外的数据:

IDictionary data=新字典
{
{“userId”,“1”},
{“用户名”,用户名},
{“isActivated”、“false”},
{“accountType”,“2”}
};
返回新的AuthenticationProperties(数据);
这不是敏感数据,我希望在调用action
GetUserInfo()
时随时可以使用此数据

[主机身份验证(DefaultAuthenticationTypes.ExternalBearer)]
[路线(“用户信息”)]
public UserInfoViewModel GetUserInfo()
{
ExternalLoginData externalLogin=ExternalLoginData.FromIdentity(User.Identity作为索赔实体);
返回新的UserInfoViewModel
{
UserName=User.Identity.GetUserName(),
HasRegistered=externalLogin==null,
LoginProvider=externalLogin!=null?externalLogin.LoginProvider:null
//我想在这里添加自定义数据
};
}

假设我可以通过该方法以某种方式检索该数据,这是错误的吗?

您可以尝试从
Athentication.AuthenticationResponseGrant
访问
AuthenticationProperties=Authentication.AuthenticationResponseGrant.properties
身份验证。调用
GetUserInfo()
时,AuthenticationResponseGrant
为空。我还缺少什么吗?为什么不把它们添加到索赔集合中?通常,在对应用程序进行身份验证时,您会将该用户的所有应用程序声明添加到集合中。@William,您能显示一些代码吗?我认为我修改的对象是为了解决我的问题,我的理解(可能是非常错误的)是AuthenticationProperties在json响应中返回,而值不在承载令牌中。因此,它只会在初始登录返回时出现。当您调用GetUserInfo传递令牌进行身份验证时,这些值将不存在,如果需要,您必须手动将这些值添加到UserInfoViewModel中,这也是可以的。如果您在AuthenticationOn时将这些值添加到声明中,则它们将位于令牌中,并且在每次调用时都可用,因为它将位于User.Identity.claims中(未检查语法)