我有一个简单的MVC 5 Owin项目,该项目使用Auth服务器进行身份验证以请求令牌。用户登录后,如何获取用户令牌以在API上发出其他受保护的请求?是否将其存储为当前记录的ClaimsIdentity的声明?
答案 0 :(得分:0)
private static string _strSISApiUrl = "YourAPIURL";
public static string GetUserAuthenticationToken(string strUserID, string strPwd)
{
#if(SISAVILABLE)
List<KeyValuePair<string,string>> objKeyValuePair= new List<KeyValuePair<string,string>>();
objKeyValuePair.Add(new KeyValuePair<string,string>("username",strUserID));
objKeyValuePair.Add(new KeyValuePair<string,string>("password",strPwd));
string jSONResult = RestHttpClient.HttpPost(_strSISApiUrl + "login", objKeyValuePair);
return jSONResult;
#else
return "{auth_token:'your api token'}";
#endif
}
答案 1 :(得分:0)
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;
}
}