c# - 如何获取经过身份验证的用户的访问令牌以进行授权的资源 api 调用?
问题描述
我有一个简单的 MVC 5 Owin 项目,它使用 Auth 服务器进行身份验证以请求令牌。用户登录后,如何获取用户的令牌以在 API 上发出其他受保护的请求?我是否将其存储为当前记录的 ClaimsIdentity 的声明?
解决方案
public class Users
{
[Required]
[StringLength(6, MinimumLength = 3)]
//[Display(Name = "User Name")]
[RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed")]
[ScaffoldColumn(false)]
public string UserName { get; set; }
[Required]
// [Display(Name = "Password")]
private string _AuthenticatedToken ;
public string Password { get; set; }
public string UserID { get; set; }
public string val { get; set; }
public string Test { get; set; }
public string AuthenticatedToken {
get {
return _AuthenticatedToken;
}
}
public bool AuthenticateUser()
{
SISInterfaceBus objSISInterfaceBus = new SISInterfaceBus();
SISValidateUserResultSet objSISValidateUserResultSet = objSISInterfaceBus.ValidateLogin(this.UserName,this.Password);
_AuthenticatedToken = objSISValidateUserResultSet.SISAuthToken;
return objSISValidateUserResultSet.IsValidUser;
}
}
推荐阅读
- php - 将多个php代码条件转换为SQL命令
- c++ - 为什么 std::unique_ptr 与赋值运算符不兼容?
- flutter - 即使更改了手机的日期和时间,如何(强制)从 Flutter 中的不同时区获取实际时间
- binary - .inf 文件包含不明确的字符!!如何阅读它的内容
- c++ - 在另一个线程中独立计时 For 循环的每个滴答声的最佳方法
- python - 没有要从文件中解析的列
- django - 我有一个错误:通过呈现模板,“NoneType”对象没有属性“价格”错误
- python - 如何使用按钮在另一个python项目中打开一个虚幻项目
- html - 导入错误:“未找到 URL 的资源”仅适用于某些特定股票
- android - 如何使用视图绑定访问 TextSwitcher 的子元素?