Created
March 3, 2017 05:53
-
-
Save lukaspili/7c5b09ec84742fc2f036b79f5bebb3ee to your computer and use it in GitHub Desktop.
ADAL iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)getToken:(void (^)(NSString*))completionBlock; | |
{ | |
ADAuthenticationError *error = nil; | |
authContext = [ADAuthenticationContext authenticationContextWithAuthority:@"https://login.microsoftonline.com/common" | |
error:&error]; | |
[authContext acquireTokenWithResource:@"https://graph.windows.net" | |
clientId:@"<Your Client ID>" // Comes from App Portal | |
redirectUri:[NSURL URLWithString:@"<Your Redirect URI>"] // Comes from App Portal | |
completionBlock:^(ADAuthenticationResult *result) | |
{ | |
if (AD_SUCCEEDED != result.status){ | |
// display error on the screen | |
[self showError:result.error.errorDetails]; | |
} | |
else{ | |
completionBlock(result.accessToken); | |
} | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:yourAppURL]; | |
NSString *authHeader = [NSString stringWithFormat:@"Bearer %@", accessToken]; | |
[request addValue:authHeader forHTTPHeaderField:@"Authorization"]; | |
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |
[NSURLConnection sendAsynchronousRequest:request | |
queue:queue | |
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) | |
{ | |
// Process Response Here | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment