Class: OmniAuth::Strategies::Valid

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/valid.rb

Overview

Instance Method Summary collapse

Instance Method Details

#callback_urlObject



119
120
121
# File 'lib/omniauth/strategies/valid.rb', line 119

def callback_url
  full_host + callback_path
end

#clientObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/omniauth/strategies/valid.rb', line 56

def client
  options.client_options[:site] = options.site

  base_url = options.site

  base_url = URI.join(base_url, "/#{request[:locale]}/") if options.with_locale_path_segment

  options.client_options[:authorize_url] = URI.join(base_url, "/o/oauth2/auth").to_s
  options.client_options[:token_url] = URI.join(base_url, "/o/oauth2/token").to_s

  options.client_options[:authorize_params] = {
    scope: :autenticacio_usuari,
    response_type: :code,
    approval_prompt: :auto,
    access_type: :online
  }
  # options.client_options[:auth_token_params] = {
  #   client_id: super.id,
  #   client_secret: super.secret,
  #   redirect_uri: callback_url
  # }
  super
end

#extraObject

extra: this method returns information not directly related with the user



47
48
49
50
51
52
53
54
# File 'lib/omniauth/strategies/valid.rb', line 47

def extra
  {
    identifier_type: raw_info["identifierType"],
    method: raw_info["method"],
    assurance_level: raw_info["assuranceLevel"],
    status: raw_info["status"]
  }
end

#raw_infoObject

The callback_phase is the second phase, after the user returns from the authentication provider site.

The result of the authentication may have ended in error, or success.

In case of success we still have to ask the authentication provider for the access_token.

That's what we do in this callback.

def callback_phase custom_log("In callback_phase with request params: #OmniAuth::Strategies::Valid.requestrequest.params") custom_log("Both should be equal otherwise a 'CSRF detected' error is raised: params state =? [#OmniAuth::Strategies::Valid.session["omniauthsession["omniauth.state"]] session state.") super end



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/omniauth/strategies/valid.rb', line 103

def raw_info
  if @raw_info
    custom_log("Access token response was: #{access_token.try(:response)}")
  else
    custom_log("Performing getUserInfo...")
    response = access_token.get(options.)
    result = [:status, :headers, :body].collect { |m| response.send(m) }
    custom_log("getUserInfo response status/headers/body: #{result}")
    @raw_info = response.parsed
    # Logout to avoid problems with Valid's cookie session when trying to login again.
    logout_url = URI.join(options.site, "/o/oauth2/logout?token=#{access_token.token}").to_s
    access_token.get(logout_url)
  end
  @raw_info
end