如何使用Python或Postman从uaa服务器获取安全令牌

时间:2015-03-05 01:55:10

标签: cloudfoundry-uaa

如何从用户名和密码的uaa服务器获取安全令牌。你能给我一些工作示例,我可以使用Python和/或Postman来做三件事: 1.登录。 2.获取令牌。 3.验证令牌。 这些uaa API文档中的端点不起作用: https://github.com/cloudfoundry/uaa/blob/master/docs/UAA-APIs.rst#verify-user-get-users-id-verify

1 个答案:

答案 0 :(得分:1)

的Python:

import requests, json, jwt
client_auth = requests.auth.HTTPBasicAuth('app', 'appclientsecret')
url = 'http://localhost:8080/uaa/oauth/token'
retval = requests.post(url=url, headers={'accept':'application/json'}, params=   {'username':'marissa','password':'koala', 'grant_type':'password','client_id':'app'}, auth=client_auth)
decode_token(json.loads(retval.content.decode('utf-8'))['access_token'])

def decode_token(token):
    print(token)
    docoded = jwt.decode(token, verify=False)
    print(decoded)

邮差:

POST /uaa/oauth/token? username=marissa&password=koala&client_id=app&grant_type=password HTTP/1.1
Host: localhost:8080
Content-Type: application/json
Authorization: Basic YXBwOmFwcGNsaWVudHNlY3JldA==
Cache-Control: no-cache