【问题标题】:Azure AD ADAuthenticationError 15 - unauthorized_client - Application is not supported for this API versionAzure AD ADAuthenticationError 15-未授权客户端-此 API 版本不支持应用程序
【发布时间】:2016-03-15 09:08:32
【问题描述】:

我需要注册我的应用才能使用 Outlook 日历 API。我在这里创建了应用程序:https://apps.dev.microsoft.com。我有应用程序 ID 和重定向 URI。然后我使用以下方法获取令牌:

[self.context acquireTokenWithResource:resourceID
                              clientId:clientID
                           redirectUri:redirectURI
                       completionBlock:^(ADAuthenticationResult *result) {
                           if (result.status !=AD_SUCCEEDED){
                               completion(result.error);
                           }

                           else{
                               self.accessToken = result.accessToken;
                               self.refreshToken = result.tokenCacheStoreItem.refreshToken;
                               self.familyName = result.tokenCacheStoreItem.userInformation.familyName;
                               self.givenName = result.tokenCacheStoreItem.userInformation.givenName;
                               self.userID = result.tokenCacheStoreItem.userInformation.userId;
                               completion(nil);
                           }
                       }];

得到了这个错误:

Error with code: 15 Domain: ADAuthenticationErrorDomain ProtocolCode:unauthorized_client Details:AADSTS70001: Application '***' is not supported for this API version.
Trace ID: c5286e11-9fa9-4ddd-96a4-a29ddd6b416c
Correlation ID: c608d556-729b-4cad-80be-24d85f5558d4
Timestamp: 2016-03-14 13:05:11Z. Inner error details: Error Domain=ADAuthenticationErrorDomain Code=15 "The operation couldn’t be completed. (ADAuthenticationErrorDomain error 15.)"

请帮我正确注册我的应用

更新: @dstrockis 帮助解决了这个问题。但现在我还有一个: 还有https://cocoapods.org/pods/ADALiOS是使用方法

 [authContext acquireTokenWithResource:resourceId
                             clientId:clientId
                          redirectUri:redirectUri
                      completionBlock:^(ADAuthenticationResult *result) {
    if (AD_SUCCEEDED != result.status){
        // display error on the screen
        [self showError:result.error.errorDetails];
    }
    else{
        completionBlock(result.accessToken);
    }
}];

但 ADALiOS 库,3.0.0-pre3 不包含此方法。我试过用

- (void)acquireTokenWithScopes:(NSArray*)scopes
          additionalScopes:(NSArray*)additionalScopes
                  clientId:(NSString*)clientId
               redirectUri:(NSURL*)redirectUri
                identifier:(ADUserIdentifier*)identifier
            promptBehavior:(ADPromptBehavior)promptBehavior
           completionBlock:(ADAuthenticationCallback)completionBlock;

我收到以下错误:“代码错误:17 域:ADAuthenticationErrorDomain ProtocolCode:(null) 详细信息:应用程序没有当前的 ViewController。内部错误详细信息:错误域 = ADAuthenticationErrorDomain 代码 = 17“操作无法' t 完成。 (ADAuthenticationErrorDomain 错误 17.)"".

【问题讨论】:

  • 这是正确的使用方法。我会看看我是否可以让我们的 iOS 人员评论那个特定的错误。您确实需要在 ViewController 的上下文中调用该方法,以便 adal 可以弹出 Web 视图来执行身份验证。
  • @dstrockis,我在我的视图控制器中调用了它,在 ViewDidLoad 方法中以前的方法“acquireTokenWithResource”我也在那里调用并显示了授权控制器
  • @dstrockis 你碰巧发现了关于这个问题的任何其他信息吗?这实际上是一个漫长的过程,所以如果您或您的 iOS 人员可以提供帮助,我们将不胜感激:)

标签: azure authentication azure-active-directory adal


【解决方案1】:

您使用了错误版本的 ADALiOS 库。为了使用 v2.0 端点(以及在 apps.dev.microsoft.com 上注册的应用程序),您需要使用 ADALiOS 库的预览版 3.0.0-pre3。见https://cocoapods.org/pods/ADALiOS。有关 v2.0 端点的更多信息,请访问 aka.ms/aaddevv2。

【讨论】:

  • 非常感谢,它帮助解决了我的问题。但是现在我还有一个问题,我是在UPDATE之后添加的
【解决方案2】:

对于您更新的问题:

您可能需要在调用 acquireTokenWithScopes 之前指定父视图控制器,以防 ADAL 找不到您的根视图控制器。

例如,设置

context.parentController = self;

在调用acquireTokenWithScopes之前。

【讨论】:

  • 感谢您的回答。我已经完成了,但它仍然无法在 iOS7 设备上运行。我有控制器,但由于请求错误而无法正常工作。在 iOS8 和更高版本的设备上,一切正常,无需 context.parentController = self
  • 文件“ADHelpers.m”中的字符串“if (query && [query containsString:ADAL_ID_VERSION])”中存在异常。我根据iOS版本重写了它。然后我看到授权控制器显示“抱歉。但我们在登录时遇到问题。我们收到了错误的请求。为输入参数“范围”提供的值无效”。我用 nil 代替了这个参数。但出现错误:“参数'范围'是必需的”。在 iOS8 和更高版本的设备上,它仅适用于 'scopes' nil,但由于令牌无效,我无法获取日历事件。
  • 我解决了 iOS7 的问题,我不得不输入“范围”“outlook.office.com/Calendars.Read”而不是“outlook.office.com/calendars.read"))
猜你喜欢
  • 2016-02-25
  • 2016-11-18
  • 2016-06-29
  • 1970-01-01
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多