Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in MsaAuthenticationProvider with "User.Read" scope #42

Open
23W opened this issue Feb 21, 2017 · 1 comment
Open

Exception in MsaAuthenticationProvider with "User.Read" scope #42

23W opened this issue Feb 21, 2017 · 1 comment

Comments

@23W
Copy link

23W commented Feb 21, 2017

Can I use MsaAuthenticationProvider for receive token for both OneDrive and Microsoft Graph services ?
I need Microsoft Graph for reading information about current logged user (because OneDrive SDK hasn't such method). But, if I add scope "User.Read" to scope array, msaAuthProvider.AuthenticateUserAsync() will generate exception after user authentication.

string AppKey = "APP_ID";
string AppRedirect = "https://login.live.com/oauth20_desktop.srf";
string[] AppScopes = { "User.Read",  "offline_access", "onedrive.readwrite" };

var msaAuthProvider = new MsaAuthenticationProvider(AppKey, AppRedirect, AppScopes, new CredentialVault(AppKey));
await msaAuthProvider.AuthenticateUserAsync();  //!< produces Microsoft.Graph.ServiceException exception after authentication

var client = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider);

Exception data:

Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary System.Collections.ListDictionaryInternal}
Error {Code: generalException Message: Unexpected exception returned from the service. } Microsoft.Graph.Error

Small addition. Such code (token for OneDrive) works fine.

var msaAuthProvider = new MsaAuthenticationProvider(AppKey, AppRedirect, new[] { "offline_access", "onedrive.readwrite" }, new CredentialVault(AppKey));
await msaAuthProvider.AuthenticateUserAsync();

Such code (token for access to User profile) works fine, too.

var msaAuthProvider = new MsaAuthenticationProvider(AppKey, AppRedirect, new[] { "User.Read" }, new CredentialVault(AppKey));
await msaAuthProvider.AuthenticateUserAsync();

But together it will generate exception. Why so?

var msaAuthProvider = new MsaAuthenticationProvider(AppKey, AppRedirect, new[] { "User.Read", "offline_access", "onedrive.readwrite" }, new CredentialVault(AppKey));
await msaAuthProvider.AuthenticateUserAsync();
@daboxu
Copy link
Contributor

daboxu commented Feb 27, 2017

hi @23W the MSA provider only works MSA OAuth which you can see it goes to login.live.com/oauth while unfortunately it won't work with Microsoft Graph Service which talks to Azure AD OAuth V2, I would suggest you use the MSAL library for talking with Microsoft Graph Service. Sorry for these confusing OAuth definitions, for detail you can see my answer here: OneDrive/onedrive-sdk-csharp#216.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants