-
Notifications
You must be signed in to change notification settings - Fork 42
Add OIDC support #4597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kieftrav
wants to merge
3
commits into
master
Choose a base branch
from
add-oidc-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add OIDC support #4597
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # rubocop:disable Metrics/BlockLength | ||
| Doorkeeper::OpenidConnect.configure do | ||
| issuer do |_resource_owner, _application| | ||
| if Rails.env.production? | ||
| 'https://panoptes.zooniverse.org' | ||
| elsif Rails.env.staging? # rubocop:disable Rails/UnknownEnv | ||
| 'https://panoptes-staging.zooniverse.org' | ||
| else | ||
| 'http://localhost:3000' | ||
| end | ||
| end | ||
|
|
||
| # Use the same RSA key that Doorkeeper::JWT uses for signing access tokens. | ||
| signing_key lambda { | ||
| key_path = Rails.root.join('config', 'keys', "doorkeeper-jwt-#{Rails.env}.pem") | ||
| File.read(key_path) | ||
| } | ||
|
|
||
| signing_algorithm :rs512 | ||
|
|
||
| # Resolve the resource owner (User) from a Doorkeeper access token. | ||
| resource_owner_from_access_token do |access_token| | ||
| User.find_by(id: access_token.resource_owner_id) | ||
| end | ||
|
|
||
| # Return the time the user last authenticated. Devise's current_sign_in_at tracks this. | ||
| auth_time_from_resource_owner do |resource_owner| | ||
| resource_owner.current_sign_in_at&.to_i | ||
| end | ||
|
|
||
| # Re-authentication handler. For the password grant flow used in development, | ||
| # the user is always freshly authenticated so we return them directly. | ||
| reauthenticate_resource_owner do |resource_owner, _return_to| | ||
| resource_owner | ||
| end | ||
|
|
||
| # OIDC subject identifier - unique, stable user ID. | ||
| subject do |resource_owner, _application| | ||
| resource_owner.id | ||
| end | ||
|
|
||
| subject_types_supported %i[public] | ||
|
|
||
| claims do | ||
| claim :login, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.login | ||
| end | ||
|
|
||
| claim :name, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.display_name | ||
| end | ||
|
|
||
| claim :credited_name, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.credited_name | ||
| end | ||
|
|
||
| claim :email, scope: :openid, response: %i[id_token user_info] do |resource_owner, _scopes, _access_token| | ||
| resource_owner.email | ||
| end | ||
|
|
||
| claim :email_verified, scope: :openid, response: %i[id_token user_info] do |resource_owner, _scopes, _access_token| | ||
| resource_owner.confirmed_at.present? | ||
| end | ||
|
|
||
| claim :admin, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.admin? | ||
| end | ||
|
|
||
| claim :created_at, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.created_at.to_i | ||
| end | ||
|
|
||
| claim :zooniverse_id, scope: :openid do |resource_owner, _scopes, _access_token| | ||
| resource_owner.zooniverse_id | ||
| end | ||
| end | ||
| end | ||
| # rubocop:enable Metrics/BlockLength |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| exit unless Rails.env.development? | ||
|
|
||
| # Non-interactive version of dev_seed_data.rb for automated setup. | ||
| # Uses a default password for the local admin user. | ||
|
|
||
| DEFAULT_PASSWORD = 'password1234' | ||
|
|
||
| Rails.logger.info "\n=== Panoptes Local Dev Setup (non-interactive) ===" | ||
|
|
||
| # Setup admin user | ||
| attrs = { | ||
| admin: true, | ||
| password: DEFAULT_PASSWORD, | ||
| login: 'zooniverse_admin', | ||
| email: 'no-reply@zooniverse.org' | ||
| } | ||
| admin = User.where(login: 'zooniverse_admin').first_or_create(attrs, &:build_identity_group) | ||
|
|
||
| if admin.persisted? | ||
| Rails.logger.info "Admin user: #{admin.login} (email: #{admin.email})" | ||
| Rails.logger.info "Password: #{DEFAULT_PASSWORD}" | ||
| else | ||
| Rails.logger.info "ERROR: Failed to create admin user: #{admin.errors.full_messages.join(', ')}" | ||
| exit 1 | ||
| end | ||
|
|
||
| # Setup Doorkeeper first-party OAuth application with openid scope | ||
| app = Doorkeeper::Application.where(name: 'DevAppClient').first_or_create do |da| | ||
| da.owner = admin | ||
| da.name = 'DevAppClient' | ||
| da.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' | ||
| da.trust_level = 2 | ||
| da.confidential = false | ||
| scopes = %i[public openid] | Doorkeeper::Panoptes::Scopes.optional | ||
| da.default_scope = scopes.map(&:to_s) | ||
| end | ||
|
|
||
| if app.persisted? | ||
| Rails.logger.info "OAuth app: #{app.name}" | ||
| Rails.logger.info "Client ID: #{app.uid}" | ||
| Rails.logger.info "\nAccess at: http://localhost:3000/oauth/applications" | ||
| else | ||
| Rails.logger.info "ERROR: Failed to create OAuth app: #{app.errors.full_messages.join(', ')}" | ||
| exit 1 | ||
| end | ||
|
|
||
| Rails.logger.info "\n=== Setup complete ===" |
22 changes: 22 additions & 0 deletions
22
db/migrate/20260420200000_create_doorkeeper_openid_connect_tables.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class CreateDoorkeeperOpenidConnectTables < ActiveRecord::Migration[7.2] | ||
| disable_ddl_transaction! | ||
|
|
||
| def change | ||
| safety_assured do | ||
| # Schema defined by doorkeeper-openid_connect; timestamps not applicable. | ||
| create_table :oauth_openid_requests do |t| # rubocop:disable Rails/CreateTableWithTimestamps | ||
| t.references :access_grant, null: false, index: true | ||
| t.string :nonce, null: false | ||
| end | ||
|
|
||
| add_foreign_key( | ||
| :oauth_openid_requests, | ||
| :oauth_access_grants, | ||
| column: :access_grant_id, | ||
| on_delete: :cascade | ||
| ) | ||
| end | ||
| end | ||
| end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20260421100000_add_pkce_to_doorkeeper_access_grants.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class AddPkceToDoorkeeperAccessGrants < ActiveRecord::Migration[6.1] | ||
| def change | ||
| add_column :oauth_access_grants, :code_challenge, :string, null: true | ||
| add_column :oauth_access_grants, :code_challenge_method, :string, null: true | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing frozen string literal comment.