2021-02-03 16:09:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-09 12:36:50 -05:00
|
|
|
Doorkeeper::OpenidConnect.configure do
|
|
|
|
issuer Gitlab.config.gitlab.url
|
|
|
|
|
2017-09-19 11:20:49 -04:00
|
|
|
signing_key Rails.application.secrets.openid_connect_signing_key
|
2016-12-09 12:36:50 -05:00
|
|
|
|
|
|
|
resource_owner_from_access_token do |access_token|
|
|
|
|
User.active.find_by(id: access_token.resource_owner_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
auth_time_from_resource_owner do |user|
|
|
|
|
user.current_sign_in_at
|
|
|
|
end
|
|
|
|
|
|
|
|
reauthenticate_resource_owner do |user, return_to|
|
|
|
|
store_location_for user, return_to
|
|
|
|
sign_out user
|
|
|
|
redirect_to new_user_session_url
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do |user|
|
2018-06-13 16:32:21 -04:00
|
|
|
user.id
|
2016-12-09 12:36:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
claims do
|
|
|
|
with_options scope: :openid do |o|
|
2018-06-13 16:32:21 -04:00
|
|
|
o.claim(:sub_legacy, response: [:id_token, :user_info]) do |user|
|
|
|
|
# provide the previously hashed 'sub' claim to allow third-party apps
|
|
|
|
# to migrate to the new unhashed value
|
|
|
|
Digest::SHA256.hexdigest "#{user.id}-#{Rails.application.secrets.secret_key_base}"
|
|
|
|
end
|
|
|
|
|
2016-12-09 12:36:50 -05:00
|
|
|
o.claim(:name) { |user| user.name }
|
|
|
|
o.claim(:nickname) { |user| user.username }
|
2019-02-06 11:48:36 -05:00
|
|
|
|
|
|
|
# Check whether the application has access to the email scope, and grant
|
|
|
|
# access to the user's primary email address if so, otherwise their
|
|
|
|
# public email address (if present)
|
|
|
|
# This allows existing solutions built for GitLab's old behavior to keep
|
|
|
|
# working without modification.
|
2020-07-09 08:08:56 -04:00
|
|
|
o.claim(:email, response: [:id_token, :user_info]) do |user, scopes|
|
2019-02-06 11:48:36 -05:00
|
|
|
scopes.exists?(:email) ? user.email : user.public_email
|
|
|
|
end
|
2020-07-09 08:08:56 -04:00
|
|
|
o.claim(:email_verified, response: [:id_token, :user_info]) do |user, scopes|
|
2019-02-06 11:48:36 -05:00
|
|
|
if scopes.exists?(:email)
|
|
|
|
user.primary_email_verified?
|
|
|
|
elsif user.public_email?
|
|
|
|
user.verified_email?(user.public_email)
|
|
|
|
else
|
|
|
|
# If there is no public email set, tell doorkicker-openid-connect to
|
|
|
|
# exclude the email_verified claim by returning nil.
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-09 12:36:50 -05:00
|
|
|
o.claim(:website) { |user| user.full_website_url if user.website_url? }
|
2017-06-29 13:06:35 -04:00
|
|
|
o.claim(:profile) { |user| Gitlab::Routing.url_helpers.user_url user }
|
2017-05-10 00:26:17 -04:00
|
|
|
o.claim(:picture) { |user| user.avatar_url(only_path: false) }
|
2021-09-02 05:11:35 -04:00
|
|
|
o.claim(:groups) { |user| user.membership_groups.joins(:route).with_route.map(&:full_path) }
|
|
|
|
o.claim(:groups_direct, response: [:id_token]) { |user| user.groups.joins(:route).with_route.map(&:full_path) }
|
2021-12-12 04:12:10 -05:00
|
|
|
o.claim('https://gitlab.org/claims/groups/owner') do |user|
|
|
|
|
user.owned_groups.joins(:route).with_route.map(&:full_path).presence
|
|
|
|
end
|
|
|
|
o.claim('https://gitlab.org/claims/groups/maintainer') do |user|
|
|
|
|
user.maintainers_groups.joins(:route).with_route.map(&:full_path).presence
|
|
|
|
end
|
|
|
|
o.claim('https://gitlab.org/claims/groups/developer') do |user|
|
|
|
|
user.developer_groups.joins(:route).with_route.map(&:full_path).presence
|
|
|
|
end
|
2016-12-09 12:36:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|