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

How to Authenticate in ASP.NET with Business Account using SDK #45

Closed
ghost opened this issue Jan 6, 2016 · 7 comments
Closed

How to Authenticate in ASP.NET with Business Account using SDK #45

ghost opened this issue Jan 6, 2016 · 7 comments

Comments

@ghost
Copy link

ghost commented Jan 6, 2016

Do you have a guide on how to do this?

I tried to use the simple authentication below
var oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
clientId,
returnUrl,
scopes);

await oneDriveClient.AuthenticateAsync();

I noticed that after creating the client, the ClientType is set as "Consumer"

I read in this Issue
#23

That I might to create a class that implements IWebAuthenticationUi
Do you have a sample for that?

many thanks
Philip

@ginach
Copy link
Contributor

ginach commented Jan 6, 2016

Correct, GetMicrosoftAccountClient returns a OneDrive Consumer client. What you'll want to look into are the static methods in BusinessClientExtensions. The auth documentation has examples of creating a OneDrive for Business client under "Azure Active Directory (AAD) authentication".

Here's an example of creating a client using client ID and return URL:

var oneDriveClient = BusinessClientExtensions.GetActiveDirectoryClient(clientId, returnUrl);

await oneDriveClient.AuthenticateAsync();

This will use the Discovery Service to look up the service resource ID for authentication as well as the correct base URL for the API endpoint. If you do know these values already you can bypass the Discovery Service by providing them directly:

var oneDriveClient = BusinessClientExtensions.GetActiveDirectoryClient(
    clientId,
    returnUrl,
    oneDriveApiEndpoint,
    serviceResourceId)

await oneDriveClient.AuthenticateAsync();

The SDK is currently using ADAL for Business authentication.

@ghost
Copy link
Author

ghost commented Jan 7, 2016

Hi Gina,

I get this exception after calling AuthenticateAsync()

{"AADSTS90014: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: aa40c0d3-81bd-426d-b010-d777dc4a8d44\r\nCorrelation ID: 445f734b-af2e-46fe-8eaf-41c52eee3974\r\nTimestamp: 2016-01-07 06:48:58Z"}

But the constructor does not accept ClientSecret and the oneDriveClient ClientSecret is readonly

@ghost
Copy link
Author

ghost commented Jan 11, 2016

I am also getting this error

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

@ginach
Copy link
Contributor

ginach commented Jan 13, 2016

Authentication using client secret isn't fully implemented yet. Issue #36 is tracking this and I'm working on it this week. Apologies for the delay.

The best way to unblock would most likely be to use ADAL directly to obtain the token and build your own IAuthenticationProvider implementation that just appends it to requests. The AdalAuthenticationProvider class is the right place to start if you want to see what's there at the moment.

@skobba
Copy link

skobba commented Jan 27, 2016

Hi @ginach, how is it going with the client secret support? I'm using the SharePointClient at the moment, but cound not figure out how to access shared files and folders in my MVC Web App. Will this be easy in the new implementation, like the Graph API? Cheers!

@zuhaibshafi
Copy link

Hi Ginach, I currently can't find a way to authenticate OneDrive from ASP.NET MVC. Is there any sample available yet?

@ginach
Copy link
Contributor

ginach commented May 26, 2016

Our webhooks sample is an example MVC app.

@ginach ginach closed this as completed May 26, 2016
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

3 participants