Skip to content

Commit

Permalink
Fix common bug in omniauth strategies
Browse files Browse the repository at this point in the history
This change fixes the configuration addressing a common bug across omniauth strategies that was introduced back in omniauth/omniauth-oauth2#70
  • Loading branch information
smcabrera authored Jul 5, 2022
2 parents 4bb3d5a + aef8d86 commit c0b0eab
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/omniauth/strategies/qualtrics.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
require "omniauth-oauth2"
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class Qualtrics < OmniAuth::Strategies::OAuth2

option :name, "qualtrics"
option :name, 'qualtrics'

option :client_options,
site: "https://co1.qualtrics.com",
authorize_url: "/oauth2/auth",
token_url: "/oauth2/token"
site: 'https://co1.qualtrics.com',
authorize_url: '/oauth2/auth',
token_url: '/oauth2/token'

# Qualtrics does use state but we want to control it rather than letting
# omniauth-oauth2 handle it.
Expand All @@ -19,26 +18,31 @@ class Qualtrics < OmniAuth::Strategies::OAuth2

info do
{
"url" => access_token.client.site
'url' => access_token.client.site
}
end

def callback_url
full_host + script_name + callback_path
end

# Override authorize_params so that we can be deliberate about the value for state
# and not use the session which is unavailable inside of an iframe for some
# browsers (ie Safari)
def authorize_params
# Only set state if it hasn't already been set
options.authorize_params[:state] ||= SecureRandom.hex(24)
params = options.authorize_params.merge(options_for("authorize"))
options.authorize_params[:scope] = 'manage:all'
params = options.authorize_params.merge(options_for('authorize'))
if OmniAuth.config.test_mode
@env ||= {}
@env["rack.session"] ||= {}
@env['rack.session'] ||= {}
end
params
end

end
end
end

OmniAuth.config.add_camelization "qualtrics", "Qualtrics"
OmniAuth.config.add_camelization 'qualtrics', 'Qualtrics'

0 comments on commit c0b0eab

Please sign in to comment.