如果您只是想针对Azure AD进行身份验证,则不需要任何移动后端 - 只需ADAL库以及适用于Azure AD中的本机应用程序的相应配置即可。到Azure的经典门户网站(https://manage.windowsazure.com)
- 登录您对所有项目
- 点击的列表中选择相应的目录:
首先,对于原生移动应用配置Azure的AD “应用程序”选项卡
- 单击页面底部的“添加”按钮
- 单击添加应用程序我的组织正在开发
- 给它一个名称,然后选择本地客户端应用程序的类型
- 输入一个有效的URI重定向URI(它可以是任何东西,但它必须是有效的)
- 点击刻度来创建应用程序。
此时,您已经创建了该应用程序。点击配置选项卡,并记下客户端ID和重定向URI。
现在可以通过替换ADAL库的客户端ID和重定向URI来使用任何示例。以下是其中一个样本的相关代码:
- (void)acquireTokenInteractive:(id)sender
{
ADTestAppSettings* settings = [ADTestAppSettings settings];
NSString* authority = [settings authority];
NSString* resource = [settings resource];
NSString* clientId = [settings clientId];
NSURL* redirectUri = [settings redirectUri];
ADUserIdentifier* identifier = [self identifier];
ADCredentialsType credType = [self credType];
BOOL validateAuthority = _validateAuthority.selectedSegmentIndex == 0;
ADAuthenticationError* error = nil;
ADAuthenticationContext* context = [[ADAuthenticationContext alloc
initWithAuthority:authority
validateAuthority:validateAuthority
error:&error];
if (!context)
{
NSString* resultText = [NSString stringWithFormat:@"Failed to create AuthenticationContext:\n%@", error];
[_resultView setText:resultText];
return;
}
[context setCredentialsType:credType];
if ([self embeddedWebView])
{
[context setWebView:_webView];
//[_authView setFrame:self.view.frame];
[UIView animateWithDuration:0.5 animations:^{
[_acquireSettingsView setHidden:YES];
[_authView setHidden:NO];
}];
}
__block BOOL fBlockHit = NO;
[context acquireTokenWithResource:resource
clientId:clientId
redirectUri:redirectUri
promptBehavior:[self promptBehavior]
userIdentifier:identifier
extraQueryParameters:nil
completionBlock:^(ADAuthenticationResult *result)
{
if (fBlockHit)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alert = [UIAlertController
alertControllerWithTitle:@"Error!"
message:@"Completion block was hit multiple times!"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
});
return;
}
fBlockHit = YES;
dispatch_async(dispatch_get_main_queue(), ^{
[self updateResultView:result];
[_webView loadHTMLString:@"<html><head></head><body>done!</body></html>" baseURL:nil];
[_authView setHidden:YES];
[self.view setNeedsDisplay];
[[NSNotificationCenter defaultCenter] postNotificationName:ADTestAppCacheChangeNotification object:self];
});
}];
}
请更新您的问题并列出所有让您困惑的项目。请尽可能描述性。 –
你想验证你的应用程序本身的访问权限还是提供一个验证身份到你的Web服务? – Paulw11
感谢您的意见。我发布的问题是我期待的最终结果。混乱是什么移动服务器在这里? 1)我怎么能实现我的最终结果。 2)上面的入门链接显示了创建新的iOS应用程序,但是如何实现已经存在的应用程序。 3)随着可可豆荚该死的错误/异常正在上升,所以我们没有其他选择没有可可豆荚。 4)我刚刚在Azure AD中创建了一个应用(如上面的入门链接所示),我需要按照我的预期输出执行哪些步骤。 –