class OmniAuth::Strategies::IdCatMobil

OAuth references:

IdCat mòbil references:

Public Instance Methods

callback_phase() click to toggle source

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.

Calls superclass method
# File lib/omniauth/strategies/idcat_mobil.rb, line 90
def callback_phase
  log("In `callback_phase` with request params: #{request.params}")
  log("Both should be equal otherwise a 'CSRF detected' error is raised: params state[#{request.params["state"]}] =? [#{session.delete("omniauth.state")}] session state.")
  super
end
callback_url() click to toggle source

The url where the provider should redirect the users to after authenticating. github.com/intridea/omniauth-oauth2/issues/81

# File lib/omniauth/strategies/idcat_mobil.rb, line 113
def callback_url
  full_host + script_name + callback_path
end
client() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/idcat_mobil.rb, line 55
def client
  options.client_options[:site] = options.site
  options.client_options[:authorize_url] = URI.join(options.site, "/o/oauth2/auth").to_s
  options.client_options[:authorize_params] = {
    scope: :autenticacio_usuari,
    response_type: :code,
    approval_prompt: :auto,
    access_type: :online,
  }
  options.client_options[:token_url] = URI.join(options.site, "/o/oauth2/token").to_s
  options.client_options[:auth_token_params] = {
    client_id: super.id,
    client_secret: super.secret,
    redirect_uri: callback_url
  }
  super
end
extra() click to toggle source

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

# File lib/omniauth/strategies/idcat_mobil.rb, line 46
def extra
  {
    identifier_type: raw_info["identifierType"],
    method: raw_info["method"],
    assurance_level: raw_info["assuranceLevel"],
    status: raw_info["status"]
  }
end
log(msg) click to toggle source
# File lib/omniauth/strategies/idcat_mobil.rb, line 117
def log(msg)
  logger.debug(msg)
end
logger() click to toggle source
# File lib/omniauth/strategies/idcat_mobil.rb, line 121
def logger
  @logger||= defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT, progname: 'idcat_mobil')
end
raw_info() click to toggle source
# File lib/omniauth/strategies/idcat_mobil.rb, line 96
def raw_info
  log("Access token response was: #{access_token.response}")
  log("Performing getUserInfo...")
  unless @raw_info
    response= access_token.get(options.user_info_path)
    result= %i(status headers body).collect  {|m| response.send(m)}
    log("getUserInfo response status/headers/body: #{result}")
    @raw_info= response.parsed
    # Logout to avoid problems with IdCat mòbil'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
request_phase() click to toggle source

The request_phase is the first phase after the setup/initialization phase.

It is implemented in the OAuth2 superclass, and does the follwing: redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))

We're overriding solely to log.

Calls superclass method
# File lib/omniauth/strategies/idcat_mobil.rb, line 79
def request_phase
  log("In `request_phase`, with params: redirect_uri=>#{callback_url}, options=>#{options.authorize_params}")
  log("`request_phase`, redirecting the user to AOC...")
  super
end