class OmniAuth::Strategies::Traity

Constants

DEFAULT_SCOPE

Public Instance Methods

appsecret_proof() click to toggle source
# File lib/omniauth/strategies/traity.rb, line 79
def appsecret_proof
  @appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, client.secret, access_token.token)
end
authorize_params() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/traity.rb, line 50
def authorize_params
  super.tap do |params|
    %w[display scope].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
      end
    end

    params[:scope] ||= DEFAULT_SCOPE
  end
end
callback_phase() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/traity.rb, line 42
def callback_phase
  with_authorization_code! do
    super
  end
rescue NoAuthorizationCodeError => e
  fail!(:no_authorization_code, e)
end
callback_url() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/traity.rb, line 38
def callback_url
  options[:callback_url] || super
end
info_options() click to toggle source
# File lib/omniauth/strategies/traity.rb, line 66
def info_options
  params = {:appsecret_proof => appsecret_proof}
  params.merge!({:locale => options[:locale]}) if options[:locale]
  { :params => params }
end
prune!(hash) click to toggle source
# File lib/omniauth/strategies/traity.rb, line 72
def prune!(hash)
  hash.delete_if do |_, value|
    prune!(value) if value.is_a?(Hash)
    value.nil? || (value.respond_to?(:empty?) && value.empty?)
  end
end
raw_info() click to toggle source
# File lib/omniauth/strategies/traity.rb, line 62
def raw_info
  @raw_info ||= access_token.get('1.0/me', info_options).parsed || {}
end

Private Instance Methods

base64_decode_url(value) click to toggle source
# File lib/omniauth/strategies/traity.rb, line 128
def base64_decode_url(value)
  value += '=' * (4 - value.size.modulo(4))
  Base64.decode64(value.tr('-_', '+/'))
end
parse_signed_request(value) click to toggle source
# File lib/omniauth/strategies/traity.rb, line 112
def parse_signed_request(value)
  signature, encoded_payload = value.split('.')
  return if signature.nil?

  decoded_hex_signature = base64_decode_url(signature)
  decoded_payload = MultiJson.decode(base64_decode_url(encoded_payload))

  if valid_signature?(client.secret, decoded_hex_signature, encoded_payload)
    decoded_payload
  end
end
valid_signature?(secret, signature, payload) click to toggle source
# File lib/omniauth/strategies/traity.rb, line 124
def valid_signature?(secret, signature, payload)
  Digest::SHA256.hexdigest("#{payload}-#{secret}") == signature
end
with_authorization_code!() { || ... } click to toggle source
# File lib/omniauth/strategies/traity.rb, line 92
def with_authorization_code!
  if request.params.key?('code')
    yield
  elsif code_from_signed_request = signed_request_from_cookie && signed_request_from_cookie['code']
    request.params['code'] = code_from_signed_request
    @authorization_code_from_signed_request_in_cookie = true
    original_provider_ignores_state = options.provider_ignores_state
    options.provider_ignores_state = true
    begin
      yield
    ensure
      request.params.delete('code')
      @authorization_code_from_signed_request_in_cookie = false
      options.provider_ignores_state = original_provider_ignores_state
    end
  else
    raise NoAuthorizationCodeError, 'must pass either a `code` (via URL or by an `tsr_XXX` signed request cookie)'
  end
end