Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/external_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ def extract_meeting_id
meeting_id
end

def extract_role(credentials)
custom_claim = ENV.fetch('OPENID_CONNECT_CUSTOM_CLAIM', 'org_details')
roles = ENV.fetch('OPENID_CONNECT_CUSTOM_CLAIM_ROLE', 'roles')
if credentials.dig('extra', 'raw_info', custom_claim)&.key?(roles)
role_name = credentials['extra']['raw_info'][custom_claim][roles]
if !role_name.blank?
role = Role.find_by(name: role_name, provider: current_provider)
return role if !role.blank?
end
end
return default_role
end

def valid_invite_token(email:)
token = cookies[:inviteToken]

Expand All @@ -171,6 +184,7 @@ def build_user_info(credentials)
{
name: credentials['info']['name'],
email: credentials['info']['email'],
role: extract_role(credentials),
language: extract_language_code(credentials['info']['locale']),
external_id: credentials['uid'],
verified: true
Expand Down
5 changes: 3 additions & 2 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

Rails.application.config.middleware.use OmniAuth::Builder do
issuer = ENV.fetch('OPENID_CONNECT_ISSUER', '')
custom_scope = ENV.fetch('OPENID_CONNECT_CUSTOM_SCOPE', '')
lb = ENV.fetch('LOADBALANCER_ENDPOINT', '')

if lb.present?
Expand All @@ -28,7 +29,7 @@
issuer_url = File.join issuer.to_s, "/#{current_provider}"

env['omniauth.strategy'].options[:issuer] = issuer_url
env['omniauth.strategy'].options[:scope] = %i[openid email profile]
env['omniauth.strategy'].options[:scope] = %i[openid email profile] + (!custom_scope.empty? ? [custom_scope.to_sym] : [])
env['omniauth.strategy'].options[:uid_field] = ENV.fetch('OPENID_CONNECT_UID_FIELD', 'sub')
env['omniauth.strategy'].options[:discovery] = true
env['omniauth.strategy'].options[:client_options].identifier = ENV.fetch('OPENID_CONNECT_CLIENT_ID')
Expand All @@ -45,7 +46,7 @@
elsif issuer.present?
provider :openid_connect,
issuer:,
scope: %i[openid email profile],
scope: %i[openid email profile] + (!custom_scope.empty? ? [custom_scope.to_sym] : []),
uid_field: ENV.fetch('OPENID_CONNECT_UID_FIELD', 'sub'),
discovery: true,
client_options: {
Expand Down
3 changes: 3 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ REDIS_URL=
#OPENID_CONNECT_ISSUER=
#OPENID_CONNECT_REDIRECT=
#OPENID_CONNECT_UID_FIELD=sub
#OPENID_CONNECT_CUSTOM_SCOPE="org_profile"
#OPENID_CONNECT_CUSTOM_CLAIM="org_details"
#OPENID_CONNECT_CUSTOM_CLAIM_ROLE="roles"

# Uncomment the following flag if you want to use EMAIL as a Unique ID backup, useful for setups with existing users who want to switch to an IDP setup.
# More information: https://github.com/bigbluebutton/greenlight/issues/5872
Expand Down