class OmniAuth::Strategies::Yconnect

An omniauth 1.0 strategy for yahoo authentication

Public Instance Methods

build_access_token() click to toggle source
# File lib/omniauth/strategies/yconnect.rb, line 56
def build_access_token
  options.token_params = {} if options.token_params.nil?
  options.auth_token_params = {} if options.auth_token_params.nil?
  params = {}
  params[:body] = {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true))
  params[:body].merge!({'grant_type' => 'authorization_code', 'code' => request.params['code']})
  params[:headers] = {'Expect'=> '' ,
                      'Authorization' => 'Basic ' + Base64::strict_encode64("#{options.client_id}:#{options.client_secret}").strip}
  params.delete "client_id"
  params.delete "client_secret"
  params.merge(token_params.to_hash(:symbolize_keys => true))
  get_token( params , deep_symbolize(options.auth_token_params))
end
get_token(params, access_token_opts={}) click to toggle source
# File lib/omniauth/strategies/yconnect.rb, line 70
def get_token(params, access_token_opts={})
  opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
  response = client.request(:post , client.token_url, params.merge(opts))
  raise Error.new(response) if client.options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
  ::OAuth2::AccessToken.from_hash(client , response.parsed.merge(access_token_opts))
end
raw_info() click to toggle source

Return info gathered from the v1/user/:id/profile API call

# File lib/omniauth/strategies/yconnect.rb, line 95
def raw_info
  return @raw_info if @raw_info
  # This is a public API and does not need signing or authentication
  url = "https://userinfo.yahooapis.jp/yconnect/v1/attribute"
  opts = {:headers => {'Authorization' => access_token.params["token_type"].camelize + ' ' + access_token.token}}
  opts[:params] = {:schema => 'openid'}
  @raw_info ||= MultiJson.decode(client.request(:get , url , opts).body)
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end
refresh!(params={}) click to toggle source

Refreshes the current Access Token

@return [AccessToken] a new AccessToken @note options should be carried over to the new AccessToken

# File lib/omniauth/strategies/yconnect.rb, line 81
def refresh!(params={})
  raise "A refresh_token is not available" unless refresh_token
  params.merge!(
                :grant_type     => 'refresh_token',
                :refresh_token  => refresh_token)
  params[:headers] = {'Expect'=> '' ,
                      'Authorization' => 'Basic ' + Base64::strict_encode64("#{options.client_id}:#{options.client_secret}").strip}
  new_token = get_token(params)
  new_token.options = client.options
  new_token
end
user_info() click to toggle source

Provide the “Profile” portion of the raw_info

# File lib/omniauth/strategies/yconnect.rb, line 108
def user_info
  @user_info ||= raw_info.nil? ? {} : raw_info
end