使用 OneDrive for Business 进行身份验证时出现问题
Problems authenticating with OneDrive for Business
我正在测试 OneDrive SDK .NET 示例应用 here. However it's unclear to me what values I need for the AadReturnUrl and AadTargetUrl constants which are used with the AdalAuthenticationProvider and OneDriveClient classes respectively. The GitHub readme for the project refers to this page,但该页面也不清楚。
另外:对于本机客户端应用程序,在 Azure AD 中配置应用程序时,重定向 URI 使用什么值?这个值是否与上面要求的 URLs 相关?
编辑:我尝试了第一条评论的建议并收到以下错误,来自 FormBrowser.SignIn 中的代码(其中 AadReturnURL = http://myactualdomain.onmicrosoft.com; 这是一个本机应用程序,如果我没有显示网页的方法,我认为这可以是 'dummy' URL:
var adalAuthProvider = new AdalAuthenticationProvider(FormBrowser.AadClientId, FormBrowser.AadReturnUrl);
this.oneDriveClient = new OneDriveClient(FormBrowser.AadTargetUrl + "/_api/v2.0", adalAuthProvider);
authTask = adalAuthProvider.AuthenticateUserAsync(FormBrowser.AadTargetUrl);
抛出异常:Microsoft.IdentityModel.Clients.ActiveDirectory.dll 中的 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException'
Microsoft.IdentityModel.Clients.ActiveDirectory 错误:4:10/24/2016 22:05:41:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a - d__0:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS50001:名为 https://myactualdomain-my.sharepoint.com/_api/v2.0 在名为 myactualdomain.onmicrosoft.com 的租户中找不到。如果租户管理员未安装应用程序或未征得租户中任何用户的同意,就会发生这种情况。您可能已将身份验证请求发送给错误的租户。
跟踪 ID:16192303-40e9-4944-b376-d25d4ff52b73
关联 ID:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a
时间戳:2016-10-24 22:05:40Z
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.VerifyAuthorizationResult()
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.PreTokenRequest()
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext()
错误代码:invalid_resource
状态码:0
OneDriveApiBrowser.vshost.exe 错误:0:10/24/2016 22:05:41:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a - d__0:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS50001 : 在名为 myactualdomain.onmicrosoft.com 的租户中找不到名为 https://myactualdomain-my.sharepoint.com/_api/v2.0 的应用程序。如果租户管理员未安装应用程序或未征得租户中任何用户的同意,就会发生这种情况。您可能已将身份验证请求发送给错误的租户。
跟踪 ID:16192303-40e9-4944-b376-d25d4ff52b73
关联 ID:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a
时间戳:2016-10-24 22:05:40Z
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.VerifyAuthorizationResult()
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.PreTokenRequest()
在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext()
错误代码:invalid_resource
状态码:0
AadTargetUrl
应该是您服务的 URL。例如,https://contoso-my.sharepoint.com/_api/v2.0/
将是 Contoso 租户上 OneDrive for Business 的 URL。您可以使用 Discovery Service.
获取有关获取目标 URL 的更多信息
AadReturnUrl
是您在 Azure 管理门户中配置的重定向 URL(正如您正确推测的那样)。对于本地应用程序,它通常类似于 http://localhost:8080
,但对于 Web 应用程序可能有所不同。您可以在 article you already linked.
中获得更多相关信息
我正在测试 OneDrive SDK .NET 示例应用 here. However it's unclear to me what values I need for the AadReturnUrl and AadTargetUrl constants which are used with the AdalAuthenticationProvider and OneDriveClient classes respectively. The GitHub readme for the project refers to this page,但该页面也不清楚。
另外:对于本机客户端应用程序,在 Azure AD 中配置应用程序时,重定向 URI 使用什么值?这个值是否与上面要求的 URLs 相关?
编辑:我尝试了第一条评论的建议并收到以下错误,来自 FormBrowser.SignIn 中的代码(其中 AadReturnURL = http://myactualdomain.onmicrosoft.com; 这是一个本机应用程序,如果我没有显示网页的方法,我认为这可以是 'dummy' URL:
var adalAuthProvider = new AdalAuthenticationProvider(FormBrowser.AadClientId, FormBrowser.AadReturnUrl);
this.oneDriveClient = new OneDriveClient(FormBrowser.AadTargetUrl + "/_api/v2.0", adalAuthProvider);
authTask = adalAuthProvider.AuthenticateUserAsync(FormBrowser.AadTargetUrl);
抛出异常:Microsoft.IdentityModel.Clients.ActiveDirectory.dll 中的 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' Microsoft.IdentityModel.Clients.ActiveDirectory 错误:4:10/24/2016 22:05:41:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a - d__0:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS50001:名为 https://myactualdomain-my.sharepoint.com/_api/v2.0 在名为 myactualdomain.onmicrosoft.com 的租户中找不到。如果租户管理员未安装应用程序或未征得租户中任何用户的同意,就会发生这种情况。您可能已将身份验证请求发送给错误的租户。 跟踪 ID:16192303-40e9-4944-b376-d25d4ff52b73 关联 ID:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a 时间戳:2016-10-24 22:05:40Z 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.VerifyAuthorizationResult() 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.PreTokenRequest() 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext() 错误代码:invalid_resource 状态码:0
OneDriveApiBrowser.vshost.exe 错误:0:10/24/2016 22:05:41:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a - d__0:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS50001 : 在名为 myactualdomain.onmicrosoft.com 的租户中找不到名为 https://myactualdomain-my.sharepoint.com/_api/v2.0 的应用程序。如果租户管理员未安装应用程序或未征得租户中任何用户的同意,就会发生这种情况。您可能已将身份验证请求发送给错误的租户。 跟踪 ID:16192303-40e9-4944-b376-d25d4ff52b73 关联 ID:e9c2c5cd-1750-4d0f-b3a2-f373f7de309a 时间戳:2016-10-24 22:05:40Z 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.VerifyAuthorizationResult() 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.PreTokenRequest() 在 Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext() 错误代码:invalid_resource 状态码:0
AadTargetUrl
应该是您服务的 URL。例如,https://contoso-my.sharepoint.com/_api/v2.0/
将是 Contoso 租户上 OneDrive for Business 的 URL。您可以使用 Discovery Service.
AadReturnUrl
是您在 Azure 管理门户中配置的重定向 URL(正如您正确推测的那样)。对于本地应用程序,它通常类似于 http://localhost:8080
,但对于 Web 应用程序可能有所不同。您可以在 article you already linked.