我正在使用Bluemix中的CF API进行连接。我验证到的OAuth端点以下:如何设置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
}
到期对这些令牌的时间比我想要的。我如何指定更短的到期日?
我不认为你作为一个用户可以控制它。令牌的持续时间由您的UAA服务器的管理员设置(全球范围内 - > https://github.com/cloudfoundry/uaa-release/blob/develop/jobs/uaa/spec#L385-L390)。它也可以基于每个客户端进行设置。不过,您正在使用'cf'客户端,该客户端旨在与cf cli配合使用,并且也由您的平台管理员进行配置,因此无法在此处进行自定义。本质上来说,要做到这一点,你需要请求一个自定义的客户端,或者做你正在做的事情,只是过早地销毁访问/刷新标记。 –
感谢您的指针。是的,这确实是一个管理级别的事情。 – user2085050