O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.67k stars 421 forks source link

Asking for reauthentication after around 90 days of use of o365 token. #823

Open SudipRai opened 2 years ago

SudipRai commented 2 years ago

As per the documentation *O365 will automatically refresh the token for you on either authentication method. The refresh token lasts 90 days but it's refreshed on each connection so as long as you connect within 90 days you can have unlimited access.

But after using the token for certain period of time, reauthenticate is needed to access the resources. So, we have to reauthenticate for the access tokens every 90 days???

guochen-code commented 2 years ago

Just curious, how do you handle connection in your code? did you get a new refresh token?

SudipRai commented 2 years ago

image

I am handling the connection like this. The connection is made every day with the automation and it works fine for around 90 days.

guochen-code commented 2 years ago

Just some thoughts for your reference, may not be correct.

In the documentation, it says: (1) the Connection Class handles the authentication. (2) If your application needs to work for more than 90 days without user interaction and without interacting with the API, then you must implement a periodic call to Connection.refresh_token before the 90 days have passed.

so, I think your code should include refresh token method, then you will see a different refresh token in your txt file. My guess is that for the past 90 days, your refresh token did not change, so it failed when it comes to expiration.

SudipRai commented 2 years ago

The refresh token is changing with the every connection made.

SudipRai commented 2 years ago

Can you provide the code sample for making the periodic call to refresh the token??

guochen-code commented 2 years ago

If your refresh token is changing. I don't know then :(

I haven't implemented by myself. Just started to use O365, but from documentation, if need to manually call that, I will go something like:

from O365.connection import Connection c1=Connection(credentials) c1.refresh_token()

then in your token txt, the refresh token should be changed.

SudipRai commented 2 years ago

Is there any way we can bulk update the data in excel sheet through json. Accessing cell one by one and updating consumes a lot of times. And also how to delete all the data from particular workbook?

alejcas commented 2 years ago

The refresh token is changing with the every connection made.

That's normal

alejcas commented 2 years ago

Is there any way we can bulk update the data in excel sheet through json. Accessing cell one by one and updating consumes a lot of times. And also how to delete all the data from particular workbook?

I think that's not implemented. Check MS Graph to see if this is possible there. If it's possible there it should be easy to implement in O365

SudipRai commented 2 years ago

Yes, we can make a JSON data and update it in the Excel file at once using Graph API. Is there any way to do it the same way in O365??

SudipRai commented 2 years ago

The refresh token is changing with the every connection made.

That's normal

Is there any other way we can automate the process without the user interaction?

alejcas commented 2 years ago

Of course implement a call once every 90 days

SudipRai commented 2 years ago

Do you mean using the Connection class ??

SudipRai commented 2 years ago

Is there any way we can bulk update the data in excel sheet through json. Accessing cell one by one and updating consumes a lot of times. And also how to delete all the data from particular workbook?

I think that's not implemented. Check MS Graph to see if this is possible there. If it's possible there it should be easy to implement in O365

You mean we can apply everything that is in Microsoft Graph API through O365 module? Can you provide me one example? Like if I want to call these Graph API : GET /me/drive/items/{id}/workbook/worksheets/{id|name} GET /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}

Here, I dont want to use the WorkBook from O365.excel.

alejcas commented 2 years ago

Just call account.con.refresh_token()