Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Passport | 21,423 | 81,272 | 3,916 | a month ago | 32 | May 20, 2022 | 364 | mit | JavaScript | |
Simple, unobtrusive authentication for Node.js. | ||||||||||
Hydra | 14,082 | 8 | a day ago | 1 | May 08, 2019 | 75 | apache-2.0 | Go | ||
OpenID Certified™ OpenID Connect and OAuth Provider written in Go - cloud native, security-first, open source API security for your infrastructure. SDKs for any language. Works with Hardware Security Modules. Compatible with MITREid. | ||||||||||
Cas | 10,147 | 2 | 306 | 7 hours ago | 127 | September 04, 2022 | 4 | apache-2.0 | Java | |
Apereo CAS - Identity & Single Sign On for all earthlings and beyond. | ||||||||||
Identityserver4 | 8,944 | 314 | 359 | 6 months ago | 99 | March 18, 2021 | apache-2.0 | C# | ||
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core | ||||||||||
Authlib | 3,678 | 162 | 147 | a day ago | 35 | April 06, 2022 | 56 | bsd-3-clause | Python | |
The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included. | ||||||||||
Openiddict Core | 3,516 | 43 | 23 | 3 days ago | 28 | August 22, 2022 | 23 | apache-2.0 | C# | |
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET | ||||||||||
Oathkeeper | 2,948 | 2 days ago | 175 | September 14, 2022 | 63 | apache-2.0 | Go | |||
A cloud native Identity & Access Proxy / API (IAP) and Access Control Decision API that authenticates, authorizes, and mutates incoming HTTP(s) requests. Inspired by the BeyondCorp / Zero Trust white paper. Written in Go. | ||||||||||
Node Oidc Provider | 2,676 | 25 | 62 | 2 days ago | 317 | September 13, 2022 | mit | JavaScript | ||
OpenID Certified™ OAuth 2.0 Authorization Server implementation for Node.js | ||||||||||
Oidc Client Js | 2,306 | 407 | 240 | a year ago | 87 | July 19, 2021 | 116 | apache-2.0 | JavaScript | |
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications | ||||||||||
Pac4j | 2,267 | 146 | 129 | 2 days ago | 96 | September 08, 2022 | apache-2.0 | Java | ||
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT... |
This library implements an OpenID Connect authentication provider for Rails applications on top of the Doorkeeper OAuth 2.0 framework.
OpenID Connect is a single-sign-on and identity layer with a growing list of server and client implementations. If you're looking for a client in Ruby check out omniauth_openid_connect.
The following parts of OpenID Connect Core 1.0 are currently supported:
In addition we also support most of OpenID Connect Discovery 1.0 for automatic configuration discovery.
Take a look at the DiscoveryController for more details on supported features.
Doorkeeper.configuration.api_only
) is not properly supported yetMake sure your application is already set up with Doorkeeper.
Add this line to your application's Gemfile
and run bundle install
:
gem 'doorkeeper-openid_connect'
Run the installation generator to update routes and create the initializer:
rails generate doorkeeper:openid_connect:install
Generate a migration for Active Record (other ORMs are currently not supported):
rails generate doorkeeper:openid_connect:migration
rake db:migrate
If you're upgrading from an earlier version, check CHANGELOG.md for upgrade instructions.
Make sure you've configured Doorkeeper before continuing.
Verify your settings in config/initializers/doorkeeper.rb
:
resource_owner_authenticator
This callback needs to returns a falsey value if the current user can't be determined:
resource_owner_authenticator do
if current_user
current_user
else
redirect_to(new_user_session_url)
nil
end
end
grant_flows
If you want to use id_token
or id_token token
response types you need to add implicit_oidc
to grant_flows
:
grant_flows %w(authorization_code implicit_oidc)
The following settings are required in config/initializers/doorkeeper_openid_connect.rb
:
issuer
https
scheme that contains scheme, host, and optionally, port number and path components and no query or fragment components.resource_owner
and application
or request passed to the block.subject
Identifier for the resource owner (i.e. the authenticated user). A locally unique and never reassigned identifier within the issuer for the end-user, which is intended to be consumed by the client. The value is a case-sensitive string and must not exceed 255 ASCII characters in length.
The database ID of the user is an acceptable choice if you don't mind leaking that information.
If you want to provide a different subject identifier to each client, use pairwise subject identifier with configurations like below.
# config/initializers/doorkeeper_openid_connect.rb
Doorkeeper::OpenidConnect.configure do
# ...
subject_types_supported [:pairwise]
subject do |resource_owner, application|
Digest::SHA256.hexdigest("#{resource_owner.id}#{URI.parse(application.redirect_uri).host}#{'your_secret_salt'}")
end
# ...
end
signing_key
openssl
command, see e.g. Generate an RSA keypair using OpenSSL.File.read
) and/or the dotenv-rails gem (in combination with ENV[...]
).signing_algorithm
:rs256
. The list of supported algorithms can be found here
resource_owner_from_access_token
The following settings are optional, but recommended for better client compatibility:
auth_time_from_resource_owner
Time
, DateTime
, or any other class that responds to to_i
max_age
parameter and the auth_time
claim.reauthenticate_resource_owner
max_age
and prompt=login
parameters.params
, redirect_to
etc.select_account_for_resource_owner
prompt=select_account
parameter.params
, redirect_to
etc.The following settings are optional:
expiration
protocol
https
for production, and http
for all other environmentsend_session_endpoint
discovery_url_options
The URL options for every available endpoint to use when generating the endpoint URL in the
discovery response. Available endpoints: authorization
, token
, revocation
,
introspection
, userinfo
, jwks
, webfinger
.
This option requires option keys with an available endpoint and URL options as value.
The default is to use the request host, just like all the other URLs in the discovery response.
This is useful when you want endpoints to use a different URL than other requests. For example, if your Doorkeeper server is behind a firewall with other servers, you might want other servers to use an "internal" URL to communicate with Doorkeeper, but you want to present an "external" URL to end-users for authentication requests. Note that this setting does not actually change the URL that your Doorkeeper server responds on - that is outside the scope of Doorkeeper.
# config/initializers/doorkeeper_openid_connect.rb
Doorkeeper::OpenidConnect.configure do
# ...
discovery_url_options do |request|
{
authorization: { host: 'host.example.com' },
jwks: { protocol: request.ssl? ? :https : :http }
}
end
# ...
end
To perform authentication over OpenID Connect, an OAuth client needs to request the openid
scope. This scope needs to be enabled using either optional_scopes
in the global Doorkeeper configuration in config/initializers/doorkeeper.rb
, or by adding it to any OAuth application's scope
attribute.
Note that any application defining its own scopes won't inherit the scopes defined in the initializer, so you might have to update existing applications as well.
See Using Scopes in the Doorkeeper wiki for more information.
Claims can be defined in a claims
block inside config/initializers/doorkeeper_openid_connect.rb
:
Doorkeeper::OpenidConnect.configure do
claims do
claim :email do |resource_owner|
resource_owner.email
end
claim :full_name do |resource_owner|
"#{resource_owner.first_name} #{resource_owner.last_name}"
end
claim :preferred_username, scope: :openid do |resource_owner, scopes, access_token|
# Pass the resource_owner's preferred_username if the application has
# `profile` scope access. Otherwise, provide a more generic alternative.
scopes.exists?(:profile) ? resource_owner.preferred_username : "summer-sun-9449"
end
claim :groups, response: [:id_token, :user_info] do |resource_owner|
resource_owner.groups
end
end
end
Each claim block will be passed:
resource_owner
, which is the return value of resource_owner_authenticator
in your initializerscopes
granted by the access token, which is an instance of Doorkeeper::OAuth::Scopes
access_token
itself, which is an instance of Doorkeeper::AccessToken
By default all custom claims are only returned from the UserInfo
endpoint and not included in the ID token. You can optionally pass a response:
keyword with one or both of the symbols :id_token
or :user_info
to specify where the claim should be returned.
You can also pass a scope:
keyword argument on each claim to specify which OAuth scope should be required to access the claim. If you define any of the defined Standard Claims they will by default use their corresponding scopes (profile
, email
, address
and phone
), and any other claims will by default use the profile
scope. Again, to use any of these scopes you need to enable them as described above.
The installation generator will update your config/routes.rb
to define all required routes:
Rails.application.routes.draw do
use_doorkeeper_openid_connect
# your routes
end
This will mount the following routes:
GET /oauth/userinfo
POST /oauth/userinfo
GET /oauth/discovery/keys
GET /.well-known/openid-configuration
GET /.well-known/webfinger
With the exception of the hard-coded /.well-known
paths (see RFC 5785) you can customize routes in the same way as with Doorkeeper, please refer to this page on their wiki.
To support clients who send nonces you have to tweak Doorkeeper's authorization view so the parameter is passed on.
If you don't already have custom templates, run this generator in your Rails application to add them:
rails generate doorkeeper:views
Then tweak the template as follows:
--- i/app/views/doorkeeper/authorizations/new.html.erb
+++ w/app/views/doorkeeper/authorizations/new.html.erb
@@ -26,6 +26,7 @@
<%= hidden_field_tag :state, @pre_auth.state %>
<%= hidden_field_tag :response_type, @pre_auth.response_type %>
<%= hidden_field_tag :scope, @pre_auth.scope %>
+ <%= hidden_field_tag :nonce, @pre_auth.nonce %>
<%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
<% end %>
<%= form_tag oauth_authorization_path, method: :delete do %>
@@ -34,6 +35,7 @@
<%= hidden_field_tag :state, @pre_auth.state %>
<%= hidden_field_tag :response_type, @pre_auth.response_type %>
<%= hidden_field_tag :scope, @pre_auth.scope %>
+ <%= hidden_field_tag :nonce, @pre_auth.nonce %>
<%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
<% end %>
</div>
We use Rails locale files for error messages and scope descriptions, see config/locales/en.yml. You can override these by adding them to your own translations in config/locale
.
Run bundle install
to setup all development dependencies.
To run all specs:
bundle exec rake spec
To generate and run migrations in the test application:
bundle exec rake migrate
To run the local engine server:
bundle exec rake server
By default, the latest Rails version is used. To use a specific version run:
rails=4.2.0 bundle update
Doorkeeper::OpenidConnect is released under the MIT License.
Initial development of this project was sponsored by PlayOn! Sports.