LoginSignup
8
7

More than 1 year has passed since last update.

ローカル環境でテストに用に起動できるSAML-IdPサーバ

Last updated at Posted at 2021-04-28

動機

SAML認証の学習、テストのためにローカルで起動するサーバが欲しかったのですが、日本語で解説してあるページが少ないため、確認方法をここに記載します。

  • https://www.npmjs.com/package/saml-idp
    • コマンドラインから起動できるテスト用のIdP(Identity Provider)です。
  • 証明書を作成するためopensslを利用します。gitbashなどで操作してください。

※SAML認証を行う簡単なサンプルを作成しました。
https://qiita.com/murasuke/items/9bf5ca8083d1da3dd66f

テスト用IdP(saml-idp)のインストールと設定

  • npmでインストールを行うため、とりあえずpackage.jsonを作成します。
npm init -y
  • saml-idpをインストール(package.jsonへ追加)します。
npm i -D saml-idp
  • IdP用証明書ファイル作成(IdPの必須ファイル)
    • 作成したファイルをプロジェクトルートに配置します。(ルートディレクトリでコマンドを実行すれば、コピーする必要はありません)
openssl req -x509 -new -newkey rsa:2048 -nodes  -keyout idp-private-key.pem -out idp-public-cert.pem -days 7300
Generating a RSA private key
  • Country Name(国名), State or Province Name(県名), Locality Name(都市名)などは、テスト用途なので適当に入力してください。
  • 出力するファイル名(idp-public-cert.pem)は、saml-idpのデフォルト名を指定しています。変更する場合は、起動時のコマンドライン指定を修正する必要があります。

作成コマンドサンプル

$ openssl req -x509 -new -newkey rsa:2048 -nodes  -keyout idp-private-key.pem -out idp-public-cert.pem -days 7300
Generating a RSA private key
.....+++++
......+++++
writing new private key to 'idp-private-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Aichi
Locality Name (eg, city) []:Nagoya
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:Test Identity Provider
Email Address []:test@example.com
  • 起動用スクリプト登録
    • package.jsonの"scripts"に、テスト用IdP起動スクリプトを追加します。
"saml-idp": "saml-idp --acs http://localhost:7000/auth/saml --aud mock-audience"

動作確認

  • テスト用Idpサーバ(saml-idp)を起動します。port:7000番でListenします
$ npm run saml-idp

> simple-saml-auth@0.0.0 saml-idp C:\Users\test\Documents\git\auth\simple-saml-auth
> saml-idp --acs http://localhost:7000/auth/saml --aud mock-audience

Listener Port:  
  localhost:7000
HTTPS Enabled:
  false

[Identity Provider]

Issuer URI:
  urn:example:idp
Sign Response Message:
  true
Encrypt Assertion:
  false
Authentication Context Class Reference:
  urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
Authentication Context Declaration:
  None
Default RelayState:
  None

[Service Provider]

Issuer URI:
  None
Audience URI:
  mock-audience
ACS URL:
  http://localhost:7000/auth/saml
SLO URL:
  None
Trust ACS URL in Request:
  true

Starting IdP server on port localhost:7000...

IdP Metadata URL:
  http://localhost:7000/metadata

SSO Bindings:
  urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST
    => http://localhost:7000/saml/sso

  urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect
    => http://localhost:7000/saml/sso

IdP server ready at
  http://localhost:7000

  • ブラウザでアクセスして下記のような画面が出ればOKです。

saml-idp.png

8
7
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
8
7