如何使用Cordova和Azure移动应用缓存身份验证令牌?
如何使用客户端流方法缓存用户的google身份验证令牌 下面的代码成功地对用户进行了身份验证,但每次用户关闭并重新打开应用程序时都会进行身份验证如何使用Cordova和Azure移动应用缓存身份验证令牌?,cordova,azure,authentication,caching,azure-mobile-services,Cordova,Azure,Authentication,Caching,Azure Mobile Services,如何使用客户端流方法缓存用户的google身份验证令牌 下面的代码成功地对用户进行了身份验证,但每次用户关闭并重新打开应用程序时都会进行身份验证 loginAzure = function (loginSuccess, handleError) { AzureDbSvc.client.login('google') .then(function () { // Obtain information about the authenticated use
loginAzure = function (loginSuccess, handleError) {
AzureDbSvc.client.login('google')
.then(function () {
// Obtain information about the authenticated use
var url = AzureDbSvc.client.applicationUrl + '/.auth/me';
var headers = new Headers();
headers.append('X-ZUMO-AUTH',
AzureDbSvc.client.currentUser.mobileServiceAuthenticationToken);
fetch(url, { headers: headers })
.then(function (data) {
var user_json = data.json();
console.log('user_json:' + user_json);
return user_json;
}).then(function (tuser) {
authUser.email = tuser[0].user_id;
for (i = 0; i < tuser[0].user_claims.length; i++) {
switch (tuser[0].user_claims[i].typ) {
case "name":
authUser.userName = tuser[0].user_claims[i].val;
break;
case "picture":
authUser.picture = tuser[0].user_claims[i].val;
break;
case "locale":
authUser.locale = tuser[0].user_claims[i].val;
break;
}
}
loginSuccess(authUser);
}
);
}, handleError);
}
loginAzure=函数(loginsucess,handleError){
AzureDbSvc.client.login('google')
.然后(函数(){
//获取有关经过身份验证的使用的信息
var url=AzureDbSvc.client.applicationUrl+'/.auth/me';
var headers=新的headers();
headers.append('X-ZUMO-AUTH',
AzureDbSvc.client.currentUser.mobileServiceAuthenticationToken);
获取(url,{headers:headers})
.then(功能(数据){
var user_json=data.json();
log('user_json:'+user_json);
返回用户_json;
}).然后(函数(tuser){
authUser.email=tuser[0]。用户id;
对于(i=0;i
非常感谢您的帮助
迈克短版:
您可以对/.auth/me的输出执行相同的操作-仅当您还没有它时才读取它。当令牌更改时,您只需读取/.auth/me。如何检查mobileServiceAuthenticationToken值以查看其是否已过期?我搜索了一下,但没有找到一个简单的解决办法。