keycloak 获取 access token validate token

import requests as req
import json

reqJson = {
    "client_id":"jwt-service",
    "client_secret": "qaaaaa-468a-4ba6-b71a-21672d1376be",
    "username": "[email protected]",
    "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 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)

 

你可能感兴趣的:(keycloak)