Slide 15
Slide 15 text
© Hitachi, Ltd. 2021. All rights reserved.
OPAのポリシー 2/3 (関数)
14
token_introspection(
access_token,
keycloak_url,
client_id,
client_secret,
) = {"status_code": status_code, "active": active} {
# Keycloakにtoken introspectionを行う関数
# Keycloakの token/introspect にpostリクエストを投げ、ステータスコードとトークン
正当性を返す
#
# Args:
# access_token (string): jwsのアクセストークン
# keycloak_url (string): Token Introspectionを行うURL。realm情報が
埋め込まれているため注意
# client_id (string): クライアントの名前。今回はbank_app
# client_secret (srting): クライアントのシークレット情報。詳しくはKeycloak
のドキュメント参照
#
# Returns:
# object: 以下2種のデータを含む
# status_code (int) : HTTPのstatus code。200が正常
# active (boolean) : トークン正当性
auth := base64.encode(concat(":", [client_id, client_secret]))
body := urlquery.encode_object({
"token_type_hint": "access_token",
"token": access_token,
})
resp := http.send({
"method": "post",
"url": keycloak_url,
"raw_body": body,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": concat(" ", ["Basic", auth]),
},
})
status_code := resp.status_code
active := resp.body.active
}