1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowershellでKeycloakのSAMLアサーション取得まで

Last updated at Posted at 2025-02-16

目的

KeyCloakのデプロイ、SAMLアサーションの設定、ユーザーの設定完了後、SAMLアサーション発行までの動作試験を素のWindowsで実行するため。

コード

# セッションオブジェクトの作成
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
# KeycloakのURL
$url_keycloak = "<http or https>://<KeycloakのURL>/realms/<レルム名>/protocol/saml/clients/<Clientsで設定した文字列>"
$username = "<Keycloakのユーザー名>"
$password = <Keycloakのパスワード>"

# ログイン画面取得リクエストの送信
$loginResponse = Invoke-WebRequest -Uri $url_keycloak -Method Get -WebSession $session

# ログイン画面に含まれるユーザー、パスワード入力フォームに情報を入力。
$form = $loginResponse.Forms[0]
$form.Fields["username"] = $username
$form.Fields["password"] = $password

# ログインリクエストの送信
$samlResponse = Invoke-WebRequest -Uri $form.action -Method Post -Body $form.Fields -WebSession $session

# 今回は表示するだけ。SAMLアサーションを使ったSSO処理の追加が必要。
Write-Output $samlResponse.Forms[0].Fields["SAMLResponse"]

注意点

  • httpsで通信する場合、証明書の設定が必要、オプションの追加が必要

その後に必要な対応

  • SAMLアサーションを使ったSSO処理の実装

使いどころ

  • セキュリティ要件で追加のアプリインストールができない場合
  • アプリチームから試験に利用可能なアプリ提供がない。又は日程的に提供されるのが先になる場合
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?