Skip to content

[feature] Debuggability, options for the /fetchattributes API call #4

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 38 additions & 9 deletions lib/omniauth/strategies/tequila.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class TequilaFail < StandardError; end
option :uid_field, :uniqueid
option :request_info, { :name => 'displayname' }
option :switchaai, false
option :additional_parameters, {}
option :additional_parameters, {} ## OBSOLETE, please use the next one
option :additional_requestauth_parameters, {}
option :additional_fetchattributes_parameters, {}

# As required by https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
info do
Expand Down Expand Up @@ -55,7 +57,7 @@ def callback_phase

missing_info = @options[:request_info].values.reject { |k| raw_info.include?(k) }
if !missing_info.empty?
log :error, 'Missing attributes in Tequila server response: ' + missing_info.join(', ')
log :error, 'Missing attributes in Tequila server response: ' + missing_info.join(', ') + ', found instead: ' + raw_info.to_s
return fail!(:invalid_info, TequilaFail.new('Invalid info from Tequila'))
end

Expand Down Expand Up @@ -95,26 +97,53 @@ def request_phase

# retrieves user attributes from the Tequila server
def fetch_attributes( request_key )
tequila_post '/fetchattributes', "key=" + request_key
body = encode_request_body([
{"key" => request_key},
additional_fetchattributes_parameters
])
tequila_post '/fetchattributes', body
end

# retrieves the request key from the Tequila server
def get_request_key
# NB: You might want to set the service and required group yourself.
request_fields = @options[:request_info].values << @options[:uid_field]
body = 'urlaccess=' + callback_url + "\nservice=" + @options[:service_name] + "\n" +
'request=' + request_fields.join(',')
body_fields = [
"urlaccess" => callback_url,
"service" => @options[:service_name],
"request" => request_fields.join(',')
]

if @options[:require_group]
body += "\nrequire=group=" + @options[:require_group]
body_fields.push ["require" => "group=" + @options[:require_group]]
end

if @options[:switchaai]
body += "\nallows=categorie=shibboleth"
body_fields.push ["allows" => "categorie=shibboleth"]
end

@options[:additional_parameters].each { |param, value| body += "\n" + param + "=" + value}
body_fields.push additional_requestauth_parameters

tequila_post '/createrequest', body
tequila_post '/createrequest', encode_request_body(body_fields)
end

def encode_request_body( body_fields )
if (body_fields.kind_of?(Array))
return body_fields.map { |fields| encode_request_body(fields) }.join('')
end
body = ""
body_fields.each { |param, value| body += param + "=" + value + "\n" }
body
end

def additional_requestauth_parameters
@options[:additional_requestauth_parameters].empty? ?
@options[:additional_parameters] :
@options[:additional_requestauth_parameters]
end

def additional_fetchattributes_parameters
@options[:additional_fetchattributes_parameters]
end

# Build a Tequila host with protocol and port
Expand Down