0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Keycloak: curl で access_token を取得

Last updated at Posted at 2025-05-09
get_access_token.sh
#
curl -X POST http://localhost:8080/realms/myrealm/protocol/openid-connect/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=password" \
  -d "client_id=myclient01" \
  -d "client_secret=U7NTfODXUhLd4K9JwAVYpTvX6ghlRIu6" \
  -d "username=scott" \
  -d "password=hello9" > access_token.json

実行

./get_access_token.sh

パスワードが違った時の実行結果

{"error":"invalid_grant","error_description":"Invalid user credentials"}

Httpie を使った場合

go_httpie.sh
URL="http://localhost:8080/realms/myrealm/protocol/openid-connect/token"
#
http --form POST $URL \
	"grant_type=password" \
	"client_id=myclient01" \
	"client_secret=U7NTfODXUhLd4K9JwAVYpTvX6ghlRIu6" \
	"username=scott" \
	"password=hello9" > access_token.json
#
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?