首页 > 解决方案 > 如何获取经过身份验证的用户的访问令牌以进行授权的资源 api 调用?

问题描述

我有一个简单的 MVC 5 Owin 项目,它使用 Auth 服务器进行身份验证以请求令牌。用户登录后,如何获取用户的令牌以在 API 上发出其他受保护的请求?我是否将其存储为当前记录的 ClaimsIdentity 的声明?

标签: c#asp.net-mvcsecurityoauth-2.0claims-based-identity

解决方案


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;
    }
}

推荐阅读