2017-08-24 62 views
0

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

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

回答

0

虽然我一直无法弄清楚如何在oauth标记上设置过期时间,但我能够用另一种方法解决我的需求。这post有答案。换句话说,我在Flask会话对象设置为永久后设置了到期。

+1

我不认为你作为一个用户可以控制它。令牌的持续时间由您的UAA服务器的管理员设置(全球范围内 - > https://github.com/cloudfoundry/uaa-release/blob/develop/jobs/uaa/spec#L385-L390)。它也可以基于每个客户端进行设置。不过,您正在使用'cf'客户端,该客户端旨在与cf cli配合使用,并且也由您的平台管理员进行配置,因此无法在此处进行自定义。本质上来说,要做到这一点,你需要请求一个自定义的客户端,或者做你正在做的事情,只是过早地销毁访问/刷新标记。 –

+0

感谢您的指针。是的,这确实是一个管理级别的事情。 – user2085050

-1

Bluemix login oauth令牌在1天内过期。您可以在某段时间后使用refreshtoken。

+0

我所看到的更像是两周。下面是从第一呼叫JSON响应: '{ “范围”: “的OpenID uaa.user cloud_controller.read password.write cloud_controller.write”, “refresh_token”: “等等,等等”, “的access_token” : “等等,等等”, “日本烟草国际公司”: “等等,等等”, “expires_in”:1209599, “token_type”: “旗手” }' 无论如何,不​​管是一天或两个星期,我”我想让过期期限低于默认情况下的期限。 – user2085050