How to sign in any Azure Active Directory (AD) user to a Shared Native app which connector to Office 365 Sharepoint Online APIs

亡梦爱人 提交于 2019-12-06 11:37:46

问题


Is it possible to set up a single "Native app" which can be used by users on different Azure accounts/directories so they can get data from their Office 365 Sharepoint Online?

We can get this working using a "Web app" because in the Azure portal where you set this up it has the "Multi-tenanted" option which can be set to Yes - the notes for this support this:

Designates whether users in external organizations are allowed to grant your app access to data in their organization's directory. This control affects only the ability to grant access. It does not affect any access that has already been granted.

And some early testing suggests this does indeed work. However this implies using an Oauth secret which must be embedded in the app and the notes here:

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code

State (in relation to the app secret):

....It should not be used in a native app, because client_secrets cannot be reliably stored on devices. It is required for web apps and web APIs, which have the ability to store the client_secret securely on the server side.

For native apps, the docs here:

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devhowto-multi-tenant-overview

State:

Native client registrations are multi-tenant by default. You don’t need to take any action to make a native client application registration multi-tenant.

Which suggests they should work in the way we desire - however when we test this with OAuth flow from an account not in the same Azure AD where the native app was setup we get the following after authenticating:

AADSTS70001: Application with identifier 'XXXXXXXXXXXXXXXXXXXXXX' was not found in the directory YYYYYYYYYYYYYYYYYYYY

So it appears this does not work. At present the only way it seems to make this work is to create a Web app and embed the client ID and secret in the native application.

Has anybody had success with multi-tenant native apps or any ideas/feedback on what I am doing wrong or could try?

UPDATE I realised there were two things wrong here: * You can actually click on the "Manifest" button in Azure and edit the raw JSON, updating the 'availableToOtherTenants' value to make it multi-tenant. * I didn't have the scope=user_impersonation in the OAuth flow.

Now it seems we can create a native app which users in other orgs/tenants can authenticate with.

UPDATE 2 OK so it turns out our app now works for some users but at least one is getting:

AADSTS65005: Invalid resource. The client has requested access to a resource which is not listed in the requested permissions in the client's application registration. Client app ID: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA. Resource value from request: https://XXX.YYYYYY.com. Resource app ID: ZZZZZZZZZZZ. List of valid resources from app registration: 00000002-0000-0000-c000-000000000000, 00000003-0000-0ff1-ce00-000000000000.\r\nTrace ID: KKKKKKKKKKKKKKKKK\r\nCorrelation ID: CCCCCCCCCCCCCCCCCCC

I can't see why it would work for one user but not another if both are in different tenant/Azure ADs to where the app is created.


回答1:


If you were developing an native app which access the multi-tenant web API which also developed by you, you can set the add the clientId of native app to the manifest of web app's manifest with knownClientApplications property. So that when other tenant's users access the multi-tenant web API, it will also register the native app to their tenant.

Refer the code sample below which demonstrates a Windows Store application calling a multi-tenant web API that is secured using Azure AD:

active-directory-dotnet-webapi-multitenant-windows-store



来源:https://stackoverflow.com/questions/42692959/how-to-sign-in-any-azure-active-directory-ad-user-to-a-shared-native-app-which

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!