
This "OneDrive - Bentley University" folder is accessed using your Bentley email address and password. Your "OneDrive - Bentley University" folder should be used to store any files related to your work at Bentley. Why do I have both a "OneDrive" folder and a "OneDrive - Bentley University" folder? To learn how to sync your "OneDrive - Bentley University" files, follow the instructions for Windows users, here and for Mac OS users, here. I use this new Refresh Token the next time I run the program, and so on.How do I sync my "OneDrive - Bentley University" files? I call the Token endpoint using that Refresh Token, and the API gives me an Access Token to use during the current session and a new Refresh Token. So basically, I have the Refresh Token always updated. PATH_TO_FILE + '/' + FILE_NAME + ':/content', headers=header) # I just overwrite the file with the new one. # ^ Save somewhere the new refresh token. Response = requests.post('', data=params)Īccess_token = response.json()
'refresh_token': refresh_token_that_you_got_in_the_previous_step This will return an Access Token and a Refresh Token. I used for this.įorm URL: grant_type=authorization_code&client_id=your_app_client_id&code=use_the_code_returned_on_previous_step
Do a POST request with type FORM URL Encoded. That URL will redirect you to the Redirect URI that you set up and with a code= something in the URL. Use the Scopes and the Redirect URI that you set up in Azure Portal. Open a browser and go to the URL below. If we add new permissions, the tokens that we have will become invalid and we have to do this manual part again. I also thought about using Selenium for this, but since it's only one time and my app will request tokens every hour (keeping the tokens fresh), I dropped that idea. There must be a programmatic way to do this, but I had no idea how to do it. Looks like to get a token for the first time we have to use a browser or emulate something like that. I did not create any Certificate or Secret. The offline_access is to be able to get the refresh token, which will be crucial to keep the app running without asking the user to login. I added User.Read, Files.ReadWrite and offline_access. In the section API permissions, you have to add all the permissions that your app will use.
You can use your own, I chose one of the suggested:
In the section Authentication, click Add a Platform and choose Desktop + devices. In the application details, in the section Overview, take note of the Application (client) ID. In Redirect URI, choose Public client/native. In Supported account types, choose the one that has personal Microsoft accounts. Azure Active Directory -> App Registrations -> Applications from personal account It's running automatically every hour and I don't need to touch it. I'm not sure if it's the best way but it is working now.