https://jupyter.org/install.html
安裝:pip install jupyterlab
啓動: jupyter notebook
如果想用來測試http請求,需要安裝requests
pip install requests
接下來測試一下get、post請求
Get access token from KeyCloak
import requests as req
import json
reqJson = {
"client_id":"my_application",
"client_secret": "xxx-4e0b-4667-8f35-xxx",
"username": "test",
"password": "xxx",
"grant_type": "password"
}
tokenUrl = 'http://localhost:8080/auth/realms/realm_gem/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)
由於生成的token是標準的json web token,所以可以反編譯出來加密前的內容,通過下面的網址可以反編譯
header = {
"Authorization": "Bearer " + accessToken
}
userinfoUrl = 'http://localhost:8080/auth/realms/realm_gem/protocol/openid-connect/userinfo'
response = req.get(userinfoUrl, headers=header)
print(response.text)
CURL的命令:
curl -d 'client_id=xxx-jwt-service' -d 'client-secret=xxx-468a-4ba6-b71a-21672d1376be' -d 'username=dsds@xxx' -d 'password=xxx' -d 'grant_type=password' -X POST 'http://localhost:8080/auth/realms/dev/protocol/openid-connect/token'
curl -H 'Authorization: bearer ' -X GET 'http://localhost:8080/auth/realms/dev/protocol/openid-connect/userinfo'