如何设置Oauth令牌过期?

时间:2017-08-24 16:25:32

标签: python oauth ibm-cloud cloudfoundry

我正在与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
}

这些令牌的到期时间比我想要的要长。如何指定较短的到期时间?

2 个答案:

答案 0 :(得分:0)

虽然我无法弄清楚如何设置oauth令牌的过期时间,但我能够用另一种方法解决我的要求。这个post有答案。也就是说,我将Flask会话对象设置为永久性后设置到期。

答案 1 :(得分:-1)

Bluemix登录oauth令牌在1天后到期。您可以在一段时间后使用refreshtoken。

相关问题