Dipendra Shekhawat
Dipendra Shekhawat

Reputation: 55

Implementation of One Drive for Business API using client_id & secrect_key

I am developing an web app to show all the content (files & folders) from One Drive account.

Currently, I am using ADAL.js library for getting the content from one drive for business. However, it prompts for login screen.

enter image description here

I somehow want to give these credentials in config file or I need to pass these credentials programatically (hardcoded).

Can anyone help me with this requirement ?

Thanks in advance

Upvotes: 0

Views: 160

Answers (2)

npradeep357
npradeep357

Reputation: 130

You can do it. After getting the HTML login page. Parse it using jsoup or other libraries(in java)(check for similar one in other languages) and get input elements from the HTML page. You should get 4 elements as username, password, CTX, and flowToken. CTX and flowTkoen are values provided to identify the session. Add username and password values and store these as name value pairs. Now send a post request to https://login.microsoftonline.com/tenantId/login with these name value pairs as body.

Replace tenantId with your web application tenant Id.

That's it, in response you will be getting an authorization code which can be used to get access token.

Upvotes: 1

Brad
Brad

Reputation: 4202

Given that such a thing is generally frowned upon I think it's only supported in the .NET ADAL library. Even with that there are restrictions around consent - if user consent is required the call will fail, and so tenant admin consent would have to be configured. See http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/ for some more details.

You're better off logging in once, consenting, and then caching the refresh token. It can then be used to get future access tokens, along with new refresh tokens that should be used to update the cached token to ensure expiration does not occur.

Upvotes: 1

Related Questions