非常に明白な何かが欠けているような気がします...
ネイティブ iOS アプリケーションで ADAL を使用しています。Azureなどへの接続など
最近まで、この流れはうまくいっていました。今日の時点で、それは壊れているように見えます。
iOS用のoffice365 sdkから取得したLogInControllerがあります。次の方法:
-(void) getTokenWith :(NSString *)resourceId : (BOOL) clearCache completionHandler:(void (^) (NSString *))completionBlock; {
if([self getCacheToken : resourceId completionHandler:completionBlock]) return;
ADAuthenticationError *error;
authContext = [ADAuthenticationContext authenticationContextWithAuthority:authority error:&error];
NSURL *redirectUri = [NSURL URLWithString:redirectUriString];
[authContext acquireTokenWithResource:resourceId
clientId:clientId
redirectUri:redirectUri
completionBlock:^(ADAuthenticationResult *result) {
if (AD_SUCCEEDED != result.status){
[self showError:result.error.errorDetails];
}
else{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:result.tokenCacheStoreItem.userInformation.userId forKey:@"LogInUser"];
[userDefaults synchronize];
completionBlock(result.accessToken);
}
}];}
rootViewController の viewDidLoad() で呼び出されるこのメソッドで呼び出すこと。
- (void)logIn {
_resourceId = [[NSUserDefaults standardUserDefaults] objectForKey:@"SharePointResourceId"];
_userURL = [NSString stringWithFormat:@"%@%@", _resourceId, SharePointResourceUserEndPoint];
LogInController *logInController = [[LogInController alloc] init];
[logInController getTokenWith:_resourceId :false completionHandler:^(NSString *token) {
if (token == nil) {
NSLog(@"newADALLogIn: No user access token exists");
} else {
//User is authenicated, Go get the Current user data object
NSString *userToken = token;
NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LogInUser"];
[userId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *completeUrl = [NSString stringWithFormat:@"%@%@%@", _userURL, userId, UserSelectProperties];
NSString *authTokenBearer = [NSString stringWithFormat:@"Bearer %@", userToken];
NSURL *URL = [NSURL URLWithString:completeUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setValue:authTokenBearer forHTTPHeaderField:@"Authorization"];
[request setValue:@"application/json" forHTTPHeaderField:@"accept"];
@try {
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//Doing UI stuff
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:operation];
}
@catch (NSException *exception) {
NSLog(@"ERROR: %@", exception);
}
}
}];}
私が今抱えている問題は、ユーザーが初めてログインしたときです。これは、o365 Web 認証ビューに適切にリダイレクトされます。ユーザーは正常に認証でき、ホーム ビュー コントローラーが表示されます。ただし、コード:
//User is authenicated, Go get the Current user data object
NSString *userToken = token;
NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LogInUser"];
[userId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *completeUrl = [NSString stringWithFormat:@"%@%@%@", _userURL, userId, UserSelectProperties];
NSString *authTokenBearer = [NSString stringWithFormat:@"Bearer %@", userToken];
NSURL *URL = [NSURL URLWithString:completeUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setValue:authTokenBearer forHTTPHeaderField:@"Authorization"];
[request setValue:@"application/json" forHTTPHeaderField:@"accept"];
@try {
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//Doing UI stuff
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:operation];
}
@catch (NSException *exception) {
NSLog(@"ERROR: %@", exception);
}
呼び出されることはありません。以前は、認証後にそのコードが実行されていました。どんな提案でも大歓迎です。