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

How to check the token validity?

Open agn-7 opened this issue 3 years ago • 4 comments

I'm looking for a way to check the token validity. For example, I've stored a long-term token (i.e. refresh token) into the DB using TokenBackend instance, but I revoke that credentials manually via microsoft account consent page or maybe it exceeds from 90 days. Now, I want to check the existing token validation.

It would be great if there was a way to check the validity of the existing tokens something like this:

class TokenBackend(BaseTokenBackend):
...

def check_token_validation(self):
   if self.token and self.token.is_validate and not self.token.is_expired:
       return True
    return False

agn-7 avatar Aug 10 '22 14:08 agn-7

I found out that there is a .is_expired property for the token, but the problem is despite the fact that I revoke the application credential using microsoft account consent page the following code returns False:

credentials = TokenBackend(user).get_token()
print(credentials.is_expired)

agn-7 avatar Aug 10 '22 17:08 agn-7

Is expired just checks the token validity based on the type of token, the token issue time and the current time.

I don’t know if there’s an api call to check that.

alejcas avatar Aug 12 '22 19:08 alejcas

@janscas Actually, I also have experience working with google api client, for this case uses calling a method named refresh() which calls the refresh token to check the validity of the token.

agn-7 avatar Aug 15 '22 08:08 agn-7

Actually, I also have experience working with google api client, for this case uses calling a method named refresh() which calls the refresh token to check the validity of the token.

This is not implemented for the moment

alejcas avatar Aug 26 '22 13:08 alejcas