Skip to content

OpenID Connect OP (IdP) sample application. Both of OpenID Provider (OP) and Relying Party (RP). Ruby on Rails 6.1

Notifications You must be signed in to change notification settings

netsphere-labs/rails-openid-connect-idp-as

 
 

Repository files navigation

●●未了

  • registration_endpoint 動的な登録の再実装
  • end_session_endpoint シングルログアウト (SLO) の実装
  • "refresh_token" grant type. トークン有効期限の延長.

Rails OpenID Connect IdP AS (former OpenID Connect OP Sample)

What's this?

A sample authorization server acting as an OpenID Connect identity provider (OP or IdP) using the openid_connect gem. The Authorization Code Flow with PKCE, the Implicit Flow and the Hybrid Flow are supported.

クライアントの開発のため、複数のユーザを切り替えて払い出す。デバッグのため、正常なレスポンスだけでなく、異常なレスポンスも返す。

See https://www.nslabs.jp/digital-identity.rhtml

Ruby on Rails 6.1.

How to Run

Requirements

This IdP does not use "omniauth-openid-connect" or "doorkeeper-openid_connect" gem.

Localhost

To run this in development mode on your local machine:

  1. Download (or fork or clone) this repo

  2. bundle install (see "Note" section below if you get "pg"-gem-related problems)

  3. config/database.yml.sample ファイルを database.yml にコピーして、適宜編集。

  4. Setup database

  # su postgres
  $ createdb --owner DBユーザ名 --encoding utf-8 openid-connect-sample_dev
  $ bin/rails db:migrate
  $ bin/rails db:seed
  1. Copy config/connect/facebook.yml.sample to facebook.yml. And Google's.

Set client_id and client_secret Sorcery による OpenID Connect Login, Facebook Login のサンプルを兼ねている。

  1. Modify config/connect/id_token/issuer.yml -- change issuer value to http://localhost:4000

  2. Run!

  $ bin/rails assets:precompile
  $ bundle exec rails server -p 3000

production 環境の場合は, 次のようにしてコンパイルする。

  $ RAILS_ENV=production bin/rails assets:precompile

次のようなシェルスクリプトを作る

export g_client_id=クライアントid
export g_client_secret=クライアントsecret
RAILS_ENV=production passenger start

使い方

  1. Facebook または Google でログインする

Admin user としてログインする。払い出すユーザは "Fake Users" から確認できる。

  1. [Register New Client...] から, RPを登録する。

redirect_uri は複数登録可能。

  1. RP側で, client_id, client_secret を登録する。

  2. RP 側からログイン可能か確認する。 この IdP では、払い出すユーザを都度選択するようになっている。

Copyright

Copyright (c) 2011 nov matake. See MIT-LICENSE for details.

Copyright (c) 2020-2021,2024 Hisashi Horikawa.

Resources

This IdP:

For more information, see readme and wiki for openid_connect gem:

OAuth 2.0 server library:

Also of interest, the corresponding sample RP:

  • Rails OpenID Connect RP Sample the Authorization Code Flow, the Implicit Flow. And, Single Logout (SLO) based on OpenID Connect RP-Initiated Logout 1.0.

Topic: OpenSSL v3.0 (Fedora 36, CentOS Stream 9)

openid_connect gem が依存する json-jwt 1.13.0 で次のエラーが発生. OpenSSL::PKey::PKeyError 型.

rsa#set_key= is incompatible with OpenSSL 3.0

OpenSSL の仕様変更により ruby/openssl v3.0 のいくつかのメソッドが取り除かれた。とはいえ、Ruby v2.x のときからそれらのメソッドは非推奨 deprecated になっており、しかも OpenSSL v3.0 との組み合わせでは動かない。

関連 issue: Add OpenSSL 3 support · Issue #100 · nov/json-jwt

Obviously, external servers will not be able to connect to an OP that is running on localhost.

On a public server

To run it on a public server, the steps are the same as for localhost, except you will set issuer in the issuer.yml config file to your domain name.

Notes

  • The Gemfile includes gem 'pg' (for PostgreSQL), but you can remove it. Nov uses PostgreSQL for his Heroku deployment, but the default DB configs are all SQLite.
  • The Facebook link won't work unless you register your app with them.

About

OpenID Connect OP (IdP) sample application. Both of OpenID Provider (OP) and Relying Party (RP). Ruby on Rails 6.1

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • Ruby 80.4%
  • HTML 11.4%
  • JavaScript 4.1%
  • API Blueprint 2.7%
  • CSS 1.2%
  • Shell 0.2%