Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import adal import urllib import requests
- ## set variables
- username = ''
- password = ''
- authorization_url = 'h
- # aka Authority
- redirect_uri = 'https://login.microsoftonline.com/login.srf'
- # from Azure AD application
- client_id = '1ec02d31-55b8-47b8-bf19-5ce082ba121c'
- # from Azure AD application
- file_url = 'https://contoso.sharepoint.com/_api/v2.0/drive/root:/myfoldername/myfilename.csv:/content'
- ## use ADAL to create token response
- token_response = adal.acquire_token_with_username_password(
- authorization_url,
- username,
- password
- )
- ## Use ADAL to create refresh token and save as text file to reuse
- refresh_token = token_response['refreshToken']
- refresh_token_file = open('refresh_token.txt', 'w')
- refresh_token_file.write(refresh_token) refresh_token_file.close()
- ## Get saved refresh token and use it to get new token response
- refresh_token = open('refresh_token.txt', 'r').read()
- token_response =
- adal.acquire_token_with_refresh_token(
- authorization_url, str(refresh_token))
- ## get access_token from token response JSON string
- access_token = token_response.get('accessToken')
- ## create http header to send access token to authenticate
- headers = {'Authorization':'BEARER ' + str(access_token)}
- ## example to upload file
- upload_file = requests.put(file_url,
- data = open('myfilename.csv', 'rb'), headers=headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement