keycloak 获取 access token validate token

 

import requests as req
import json

reqJson = {
    "client_id":"jwt-service",
    "client_secret": "qaaaaa-468a-4ba6-b71a-21672d1376be",
    "username": "aaa@aaa.com",
    "password": "123123",
    "grant_type": "password"
}

tokenUrl = 'http://localhost:8080/auth/realms/dev/protocol/openid-connect/token'

header = {
    "Content-Type": "application/x-www-form-urlencoded",
} 

response = req.post(tokenUrl, data=reqJson, headers=header)
if response.status_code > 200:
    print (response.text)
else:
    accessToken = json.loads(response.text)['access_token']
    print(accessToken)

 

validate the token

 

 header = {
    "Authorization": "Bearer " + access_token
} 
userinfoUrl = 'https://localhost:8080/auth/realms/customer/protocol/openid-connect/userinfo'

response = req.get(userinfoUrl, headers=header)    
print(response.text)

 

posted @ 2020-08-09 10:38  冰凌花花~  阅读(837)  评论(0编辑  收藏  举报