【问题标题】:How to set Oauth token expiration?如何设置 Oauth 令牌过期?
【发布时间】:2017-08-26 01:07:39
【问题描述】:

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

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

【问题讨论】:

    标签: python oauth ibm-cloud cloud-foundry


    【解决方案1】:

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

    【讨论】:

    • 我认为您作为用户无法控制它。令牌的持续时间由您的 UAA 服务器的管理员设置(在此处全局设置 -> github.com/cloudfoundry/uaa-release/blob/develop/jobs/uaa/…)。它也可以基于每个客户端进行设置。不过,您正在使用cf 客户端,该客户端旨在与 cf cli 一起使用,并且也由您的平台管理员配置,因此也无法在那里对其进行自定义。从本质上讲,要完成这项工作,您要么需要一个自定义客户端,要么做你正在做的事情,然后过早地销毁访问/刷新令牌。
    • 感谢您的指点。是的,这确实是管理员级别的事情。
    【解决方案2】:

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

    【讨论】:

    • 我看到的更像是两个星期。这是第一次调用的 JSON 响应:{ "scope": "openid uaa.user cloud_controller.read password.write cloud_controller.write", "refresh_token": "blah, blah", "access_token": "blah, blah", "jti": "blah, blah", "expires_in": 1209599, "token_type": "bearer" } 不管是一天还是两周,我都希望将有效期设置为小于默认情况下得到的时间。
    猜你喜欢
    • 1970-01-01
    • 2016-11-29
    • 2012-04-05
    • 2016-09-10
    • 1970-01-01
    • 2015-11-04
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多