Can Azure AD ADAL (ios) refresh token be revoked from the client?

爷,独闯天下 提交于 2019-12-06 14:37:41
Gaurav Mantri

Yes. From Best Practices for OAuth 2.0 in Azure AD:

Refresh tokens do not have specified lifetimes. Typically, the lifetimes of refresh tokens are relatively long. However, in some cases, refresh tokens expire, are revoked, or lack sufficient privileges for the desired action. The client application needs to expect and handle errors returned by the token issuance endpoint correctly. When you receive a response with a refresh token error, discard the current refresh token and request a new authorization code or access token. In particular, when using a refresh token in the Authorization Code Grant flow, if you receive a response with the interaction_required or invalid_grant error codes, discard the refresh token and request a new authorization code.

Also I remember Vittorio mentioning in his blog post (ADAL 3 didn’t return refresh tokens for ~5 months… and nobody noticed) that ADAL 3 doesn't even return refresh tokens. I guess the general recommendation is not to take any dependency on refresh tokens in your application.

Regarding logging out the user, please see this thread: ADAL: W8.1 app trying to log user out, though this thread is for Windows Phone app.

Based on the link Gaurav provided, here is the logout code for ADAL Objective-c, for the sample app provided by Azure AD:

In viewcontroller:

- (IBAction)logoutUser:(id)sender
{
    [self.unifiedEndpointClient logoutUser];
}

In O365UnifiedEndpointOperations:

-(void)logoutUser
{
    AuthenticationManager *authenticationManager = [AuthenticationManager sharedInstance];
    [authenticationManager removeTokenWithResourceId:_resourceID
                                          withTenant:TENANT_STRING];
}

In AuthenticationManager:

-(void) removeTokenWithResourceId:(NSString *)resourceId
                       withTenant:(NSString *)tenant
{
    [self.authContext.tokenCacheStore removeAllWithError:nil];

    NSURLSession *urlSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration defaultSessionConfiguration]
                                                             delegate: nil
                                                        delegateQueue: [NSOperationQueue mainQueue]];
    NSURL *url = [NSURL URLWithString: [NSString stringWithFormat: @"https://login.windows.net/%@/oauth2/logout", tenant]];
    [[urlSession dataTaskWithURL:url
               completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
               {
               }] resume];
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!