0

我正在开发mobile app使用azure-mobile-apps科罗拉多客户端。我跟着这个https://cgillum.tech/2016/08/10/app-service-auth-and-azure-ad-b2c-part-2/获得刷新令牌。使用azure-mobile-apps科尔多瓦客户端刷新令牌和注销

我在标头中发送id_token。

var token = window.localStorage.getItem("token"); 
var appUrl = https://Mobile****.azurewebsites.net; 
var url = appUrl + "/.auth/refresh"; 
$http.get(url, { 
    headers: { 
     'X-ZUMO-AUTH': token 
    } 
}) 
.then(function(response) { 
    console.log(response); 
}); 

响应:401未经授权。 IDX10500:签名验证失败。 无法解析SecurityKeyIdentifier ...

我比较了资源管理器和Tenant - > Application - > Keys中的密钥。

两者都是相同的。 我也想问一下关于注销的问题,我们可以在这个端点/.auth/logout上发送同样的内容。

+0

嗨@devangi,任何更新? –

+0

嗨,对不起,请延迟。是的,我想问一下这些令牌(mobileServiceAuthenticationToken,id_token&refresh_token)?过期时间,id_token&refresh_token可通过/.auth/me端点获得。 我的观察是,即使您在1小时内分享任何没有使用mobileServiceAuthenticationToken(使用/.auth/refresh),但过期时间将会相同(在/.auth/me)。 如果您使用旧令牌调用/.auth/refresh,一小时后,它会给内部服务器提供500个错误。那么什么是mobileServiceAuthentication令牌的生命周期,id_token&refresh_token? – devangi

+0

关于如何保持用户永久登录,您可以参考[此线程](http://stackoverflow.com/questions/41310757/mobileservices-web-js-unauthorized-api-call)。 –

回答

1

为了让/.auth/refresh正常工作,就像之前提到的@mattchenderson一样,请确保client.currentUser.mobileServiceAuthenticationToken已通过X-ZUMO-AUTH标题。

要注销,您可以使用build-in SDK的注销功能。 请尝试使用以下代码将用户注销到移动应用程序中。

client.logout().then(function() { 
    window.cookies.clear(function() { 
     $state.go('index'); 
    });   
}); 

注: Web视图已存储在Cookie中的登录信息,并通过你的身份验证提供者下次登录时,浏览器会自动读取cookie和完成登录流程。所以请确保在注销时cookie被清除。我用Phonegap-Cookies-Plugin来完成这项工作。请注意,它适用于PhoneGap和Cordova。

+0

感谢您的回应,它已经解决了注销和刷新令牌。 – devangi

1

X-ZUMO-AUTH标头中提交的令牌应始终为App Service令牌,而不是AAD ID令牌。使用Mobile Apps SDK的client.login()方法之一获得此令牌。您可以从客户端对象访问此令牌(通过client.currentUser.mobileServiceAuthenticationToken)。

+0

谢谢你的回应,是的,它解决了。 – devangi

相关问题