2017-08-24 231 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