python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

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

Open SudipRai opened this issue 3 years ago • 15 comments

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???

SudipRai avatar Aug 18 '22 16:08 SudipRai

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

guochen-code avatar Aug 18 '22 17:08 guochen-code

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.

SudipRai avatar Aug 19 '22 03:08 SudipRai

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.

guochen-code avatar Aug 19 '22 04:08 guochen-code

The refresh token is changing with the every connection made.

SudipRai avatar Aug 19 '22 04:08 SudipRai

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

SudipRai avatar Aug 19 '22 04:08 SudipRai

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.

guochen-code avatar Aug 19 '22 05:08 guochen-code

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?

SudipRai avatar Aug 31 '22 10:08 SudipRai

The refresh token is changing with the every connection made.

That's normal

alejcas avatar Sep 09 '22 07:09 alejcas

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

alejcas avatar Sep 09 '22 07:09 alejcas

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 avatar Sep 10 '22 15:09 SudipRai

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?

SudipRai avatar Sep 10 '22 15:09 SudipRai

Of course implement a call once every 90 days

alejcas avatar Sep 10 '22 16:09 alejcas

Do you mean using the Connection class ??

SudipRai avatar Sep 10 '22 16:09 SudipRai

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.

SudipRai avatar Sep 10 '22 17:09 SudipRai

Just call account.con.refresh_token()

alejcas avatar Sep 10 '22 17:09 alejcas