我试图实施"记住我"特征
我尝试使用refresh_token。
在开始时,用户获取refresh_token,access_token及其expire_time。
如果access_token的expire_time结束,我在http_service中给出了401错误。但是,我想在那种情况下刷新access_token。
问题是:虽然参数"内容"填充,它不能传递到APP端。我的意思是" OAuthValidateClientAuthenticationContext context" '参数'计数为零。这只在获得401错误后才会发生。我的意思是当发出401错误时,帖子请求无法正常工作。我不明白为什么内容没有传递到APP方面?有人可以帮帮我吗?
我使用了这段代码:
UI
if (error.status == 401) { //Unauthorized
if (localStorage.getItem("refresh_token")) // Remember me için kontrol !
{
let content: any = {};
let loginUrl: any = "vbsecure/token";
content.refresh_token = localStorage.getItem("refresh_token");
content.grant_type = "refresh_token";
content.rememberMe = localStorage.getItem("rememberme");
console.log("content", content);
this.post(loginUrl, content, ContentTypes.URLENCODED).subscribe(
tp => {
if (!!tp) {
sessionStorage.setItem('access_token', tp.access_token);
sessionStorage.setItem('token_type', tp.token_type);
localStorage.setItem('access_token', tp.access_token);
localStorage.setItem('token_type', tp.token_type);
console.log("TP", tp);
//this.loggedIn = true;
this.router.navigate(['']);
}
},
err => {
console.log("http.service 401 içindeki hata");
//this.ems.onShowDialog.next({ content: "Hatalı kullanıcı adı / şifre", title: "Hata" });
this.router.navigate(['login']);
});
}
应用
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
var allowedOrigin = "*";
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
context.OwinContext.Response.Headers.Add("Accept", new[] { "text/html", "application/xhtml+xml", "*/*" });
if (context.Parameters.Get("rememberMe") != "undefined")
{
_rememberMe = Convert.ToBoolean(context.Parameters.Get("rememberMe"));
HttpContext.Current.Items.Add("_rememberMe", _rememberMe);
}
context.Validated();
return Task.FromResult<object>(null);
}