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?

OpenID Connectのテスト用としてKeycloakをOpenID Providerとして用意する方法

Last updated at Posted at 2025-11-29

Keyclaokの起動

ブラウザ-https->docker-compose(nginx-http->keycloak)とつながるように用意しました
自己証明書作成(もしくは証明書を入手)

$ mkdir -p certs
$ openssl req -newkey rsa:2048 -nodes -keyout certs/key.pem -x509 -days 365 -out certs/cert.pem

nginx.confを作成

events {}

http {
    server {
        listen 443 ssl;
        ssl_certificate     /etc/nginx/certs/cert.pem;
        ssl_certificate_key /etc/nginx/certs/key.pem;

        location / {
            proxy_pass http://keycloak:8080;
        }
    }
}

docker-compose.ymlを用意しました。

services:
  keycloak:
    image: quay.io/keycloak/keycloak:latest
    volumes:
      - "./keycloak_data:/opt/keycloak/data"
    command: start-dev --hostname=localhost --http-enabled=true --hostname=https://mydomain.example.com
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
    ports:
      - "8080:8080"

  nginx:
    image: nginx:alpine
    ports:
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certs:/etc/nginx/certs:ro

keycloak_dataディレクトリを777で作成し、
起動は$ docker compose upで行いました。

KeyclaokをOpenID Providerとして用意する

Realmを作成しました。
keyclaok2-1realm.png

Clientを作成しました。このClient IDをRelaying Party(RP)側で使います。
keyclaok2-2client1.png

Standard flowが認可フロー(Authentication flow)の意味です。
keyclaok2-3client2.png

保存します。
keyclaok2-4client3.png

Client SecretもRelaying Party(RP)側で使うため調べます。
keyclaok2-4.5client4.png

OpenID ProvierのKeycloakがリダイレクトする先のURLを設定します。(ここに記載したURLにしかリダイレクトできません。)
keyclaok2-5.5validredirectURLs.png

AWS Cognito user poolをRelaying Party(RP)としてフェデレーションさせる

外部プロバイダーとして登録

AWS Cognito user poolの外部プロバイダーを追加します。
OpenID Provider(Keycloak)側で調べておいたクライアントIDとクライアントシークレットを入力します。
発行者URLは、https://(Keycoakサーバ)/realms/(realm名) になります。
keyclaok2-8cognito3.png

アプリケーションクライアントからフェデレーション先を設定

ログインページを編集します。
keyclaok2-9cognito4.png

IDプロバイダーを指定します。
keyclaok2-10cognito5.png

ログインページは次のようになります。
keyclaok2-11cognito-login.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?