2

I am trying to use the OneDrive API Python SDK to upload files to an Office 365 E3 account SharePoint folder.

As described for OneDrive for business / SharePoint files I am using Azure AD that is included in my Office 365 E3 account for auth and have created a native client application app in Azure AD management.

I would expect that I need to point auth to Office 365:

mydomain.sharepoint.com

However, it appears the OneDrive API Python SDK (auth_provider.py) points auth to:

AUTH_SERVER_URL = "https://login.live.com/oauth20_authorize.srf"
AUTH_TOKEN_URL = "https://login.live.com/oauth20_token.srf"

This Github issue discussion indicates OneDrive API Business is still in beta but just changing base urls to mydomain.sharepoint.com urls is all that is needed to use SDK for OneDrive API Business eg:

AUTH_SERVER_URL = "https://mydomain.sharepoint.com/oauth20_authorize.srf"
AUTH_TOKEN_URL = "https://mydomain.sharepoint.com/oauth20_token.srf"

Is this correct?

Edited to ensure related additional questions are addressed too:

Is there anything else other than the auth urls that needs to be modified in the OneDrive API Python SDK to be used for OneDrive for Business / Sharepoint?

The Github README includes sample code for authentication which requires client_secret and scopes to be identified.

However the Azure Active Directory app creation process includes scope identification, and native client app doesn't require client_secret.

For my native client app authorization, I have just left client_secret and scopes blank in the sample code eg:

client_secret = ""
client = onedrivesdk.get_default_client(client_id='xxxxxetc', 
                                            scopes=[])
curtisp
  • 2,227
  • 3
  • 30
  • 62

2 Answers2

1

Auth for OneDrive for Business is handled by AAD, which means you need to point to the AAD OAuth 2 end points, which are:

AUTH_SERVER_URL = "https://login.microsoftonline.com/common/oauth2/authorize"
AUTH_TOKEN_URL = "https://login.microsoftonline.com/common/oauth2/token"

This is roughly documented here, https://dev.onedrive.com/auth/aad_oauth.htm, although since that is describing the authentication flow the details are a bit hidden if you were just looking for the two URLs to use with the SDK.

Ryan Gregg
  • 2,015
  • 13
  • 16
  • Thanks I did scan over the auth flow and missed those two urls. Is there anything else other than the auth urls that needs to be modified in the OneDrive API Python SDK to be used for OneDrive for Business / Sharepoint? I modified my question to include this. – curtisp May 16 '16 at 04:14
1

If you take a look at the onedrivesdk_helpers module, you'll see that it defaults to api.onedrive.com. I would recommend using the following code in place of get_default_client:

http_provider = HttpProvider()
auth_provider = AuthProvider(http_provider=http_provider,
                             client_id="your_app_id",
                             scopes=[])
client = OneDriveClient("mydomain.sharepoint.com",
                        auth_provider,
                        http_provider)

Make sure to import those classes with from onedrivesdk import HttpProvider, AuthProvider, OneDriveClient

cmayer-ms
  • 116
  • 2
  • Ok that helped. Now it's running but blocking in `GetAuthCodeServer.py` in `GetAuthCodeServer` returning ` `socket.error: [Errno 10049] The requested address is not valid in its context` I believe on the redirect_uri which doesn't exist (it's native client app). When I manually create auth_url into browser, it returns code in url though page shows `404 NOT FOUND`. How can I get it to return code to complete auth? – curtisp May 17 '16 at 02:02
  • I guess using this Python SDK for native client app is problematic. Also`get_auth_code` requires opening browser `webbrowser.open(auth_url)` to get auth code. – curtisp May 17 '16 at 02:52
  • If you're writing a native client app then I would not recommend using `GetAuthCodeServer` for the exact reason you mentioned (using `webbrowser.open()`). At this point you are performing steps for OAuth. I would recommend looking at other examples of OAuth and Python on your platform. – cmayer-ms May 17 '16 at 22:28