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?

More than 1 year has passed since last update.

Keycloakを利用した多要素認証(OTP認証)

Posted at

Keycloakを利用した多要素認証(OTP認証)

  • Windows 10 Pro
  • JDK 17(Eclipse pleiades 同梱のJDK17)
  • Keycloak 20.0.3(2023/1/14時点最新)

Windows対応版のKeycloakセットアップ

Keycloakのダウンロード

keycloak本体を以下よりダウンロード
https://github.com/keycloak/keycloak/releases/download/20.0.3/keycloak-20.0.3.zip

Windows10のローカルドライブの下記フォルダへzipを展開
C:\tools\keycloak\keycloak-20.0.3

Keycloakを起動する

JDKをインストールしていないため、Eclipse pleiadesに同梱されているJDK17を利用するように、keycloak起動用のbatファイルを修正し、JAVA_HOMEの設定を追加。

C:\tools\keycloak\keycloak-20.0.3\bin\kc.bat
@echo off
rem -------------------------------------------------------------------------
rem Keycloak Startup Script
rem -------------------------------------------------------------------------

rem 以下の設定を追加
set JAVA_HOME=C:\eclipse\pleiades-2022-06\java\17
set PATH=%JAVA_HOME%\bin;%PATH%

コマンドプロンプトを起動して以下のコマンドを実行しkeycloakを起動する。

C:\tools\keycloak\keycloak-20.0.3\bin\kc.bat start-dev

Keycloak Admin Console利用のための初期設定

http://localhost:8080/
にアクセスしてAdmin ConsoleのユーザーをCreateする。
image.png

Admin Consoleにアクセスして、作成した管理者でログインする。
image.png

OTP(One Time Password)認証のためのレルム作成

画面左上にあるコンボボックスを選択してCreate Realmボタンを押下
image.png

任意のレルム名を設定してCreateボタンを押下
image.png

OTP認証の設定

Authentication -> Flows -> Policiesタブ -> OTP Policy で任意の設定項目を変更する。
公式のTOTP configuration optionsを参考に設定を検討する。
image.png

Keycloakに動作検証用のユーザーを追加してOTP認証の動作確認

Create new user ボタンを押下
image.png

任意のユーザーを追加
image.png

追加したユーザーの初期パスワードを設定
image.png

以下にアクセスして、作成したユーザーでサインインする。
http://localhost:8080/realms/otp-sample/account

サインインするとこんな画面が出てきます。
image.png

Google Authenticatorが利用できるアプリの候補に出てきていないので、FreeOTPのツールをスマホにインストールして、QRコードを読み込みワンタイムパスワードを入力することで無事ログインできることを確認できました。
image.png

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?