使用Microsoft Graph和如何操作时是否需要刷新访问令牌?

时间:2016-12-08 08:36:04

标签: token access-token microsoft-graph refresh-token

我在我的iOS应用程序中使用Microsoft Graph SDK。

我是否需要在过期后手动刷新访问令牌?

我正在谈论的访问令牌是: NXOAuth2AccountStore.sharedStore()。帐户[0] .accessToken

我已经测试过即使accessToken过期我仍然可以查询。在我第一次登录时,过期时间是3600秒。所以,我等了2个小时,测试再次获取用户信息,事件仍然可以得到它。

我有转储" accessToken.hasExpired"和" accessToken.expiresAt"确保访问令牌已过期

由于

*更多细节*

我在这里关注示例: https://github.com/microsoftgraph/ios-swift-connect-sample

我在Microsoft Graph上找不到任何有关刷新访问令牌的文档: https://graph.microsoft.io/en-us/code-samples-and-sdks

2 个答案:

答案 0 :(得分:2)

是的,在应用程序中使用Graph时,需要定期刷新令牌。 Azure AD的网站提供了更详细的文档:https://docs.microsoft.com/en-us/azure/active-directory/active-directory-authentication-scenarios

您使用的建议的auth库包含一个刷新此令牌的方法:

@implementation NXOAuth2AuthenticatorRefreshCallback

如果我没有回答你的问题,你能否更具体地说明你想要完成的事情?您是否可以使用过期的令牌,或者您无法刷新旧令牌?

答案 1 :(得分:0)

每当需要刷新访问令牌时,请使用此代码。 这将作为图形sdk中提供的预定义代码的补丁,您可以从方法中提取令牌:

+(id)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSString *)tokenType;

[MSGraphClient setAuthenticationProvider:AppDel.authentication.authProvider];

_graphClient = [MSGraphClient client];

NSMutableURLRequest * sampleReq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://graph.microsoft.com/v1.0/me"]];

[_graphClient.authenticationProvider appendAuthenticationHeaders:sampleReq completion:^(NSMutableURLRequest *request, NSError *error){    
    if(error == nil)
    {

    }
    else
    {
        [self showToast:@"" message:@"Failure in refresh 0365 token"];
    }
}];