如何设置 Oauth 令牌过期?
How to set Oauth token expiration?
我正在与 Bluemix 的 CF API 进行交互。我使用以下内容对 OAuth 端点进行身份验证:
oauth_endpoint = 'https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token'
http_headers = {
'Authorization': 'Basic Y2Y6'
}
http_payload = {
'grant_type': 'password',
'username': user,
'password': pw
}
response = requests.post(oauth_endpoint, data=http_payload, headers=http_headers)
results = response.json()
authorization = results['token_type'] + ' ' + results['access_token']
authorized_headers = {
'Authorization': authorization
}
然后刷新令牌:
http_refresh_payload = {
'grant_type': 'refresh_token',
'refresh_token': results['refresh_token']
}
response = requests.post(oauth_endpoint, data=http_refresh_payload, headers=http_headers)
results = response.json()
authorization = results['token_type'] + ' ' + results['access_token']
authorized_headers = {
'Authorization': authorization
}
这些令牌的到期时间比我想要的要长。如何指定较短的到期时间?
Bluemix 登录 oauth 令牌将在 1 天后过期。您可以在一段时间后使用刷新令牌。
虽然我一直无法弄清楚如何设置 oauth 令牌的到期时间,但我能够使用替代方法解决我的要求。这个 post 有答案。也就是说,我在 Flask 会话对象永久化后设置了过期时间。
我正在与 Bluemix 的 CF API 进行交互。我使用以下内容对 OAuth 端点进行身份验证:
oauth_endpoint = 'https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token'
http_headers = {
'Authorization': 'Basic Y2Y6'
}
http_payload = {
'grant_type': 'password',
'username': user,
'password': pw
}
response = requests.post(oauth_endpoint, data=http_payload, headers=http_headers)
results = response.json()
authorization = results['token_type'] + ' ' + results['access_token']
authorized_headers = {
'Authorization': authorization
}
然后刷新令牌:
http_refresh_payload = {
'grant_type': 'refresh_token',
'refresh_token': results['refresh_token']
}
response = requests.post(oauth_endpoint, data=http_refresh_payload, headers=http_headers)
results = response.json()
authorization = results['token_type'] + ' ' + results['access_token']
authorized_headers = {
'Authorization': authorization
}
这些令牌的到期时间比我想要的要长。如何指定较短的到期时间?
Bluemix 登录 oauth 令牌将在 1 天后过期。您可以在一段时间后使用刷新令牌。
虽然我一直无法弄清楚如何设置 oauth 令牌的到期时间,但我能够使用替代方法解决我的要求。这个 post 有答案。也就是说,我在 Flask 会话对象永久化后设置了过期时间。