def blender_id_server_validate(token) -> typing.Tuple[typing.Optional[str], typing.Optional[str]]:
"""Validate the auth token with the server.
@param token: the authentication token
@type token: str
@returns: tuple (expiry, error).
The expiry is the expiry date of the token if it is valid, else None.
The error is None if the token is valid, or an error message when it's invalid.
"""
import requests
import requests.exceptions
try:
r = requests.post(blender_id_endpoint('u/validate_token'),
data={'token': token}, verify=True)
except requests.exceptions.RequestException as e:
return (str(e), None)
if r.status_code != 200:
return (None, 'Authentication token invalid')
response = r.json()
return (response['token_expires'], None)
评论列表
文章目录