Class: OmniAuth::Strategies::Orkut

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/orkut.rb

Overview

Authenticate to Orkut via OAuth and retrieve basic user info.

Usage:

use OmniAuth::Strategies::Orkut, 'consumerkey', 'consumersecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Orkut

Returns a new instance of Orkut.



14
15
16
17
18
19
20
21
22
# File 'lib/omniauth/strategies/oauth/orkut.rb', line 14

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  client_options = {
    :site => 'https://www.google.com',
    :request_token_path => '/accounts/OAuthGetRequestToken',
    :access_token_path => '/accounts/OAuthGetAccessToken',
    :authorize_path => '/accounts/OAuthAuthorizeToken'
  }
  super(app, :orkut, consumer_key, consumer_secret, client_options, options)
end

Instance Method Details

#auth_hashObject



24
25
26
27
28
29
30
31
# File 'lib/omniauth/strategies/oauth/orkut.rb', line 24

def auth_hash
  ui = 
  OmniAuth::Utils.deep_merge(super, {
    'uid' => ui['uid'],
    'user_info' => ui,
    'extra' => {'user_hash' => user_hash}
  })
end

#request_phaseObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/omniauth/strategies/oauth/orkut.rb', line 47

def request_phase
  request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://orkut.gmodules.com/social/rest'})
  session['oauth'] ||= {}
  session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
  r = Rack::Response.new

  if request_token.callback_confirmed?
    r.redirect(request_token.authorize_url)
  else
    r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
  end

  r.finish
end

#user_hashObject



43
44
45
# File 'lib/omniauth/strategies/oauth/orkut.rb', line 43

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get("http://www.orkut.com/social/rest/people/@me/@self").body)
end

#user_infoObject



33
34
35
36
37
38
39
40
41
# File 'lib/omniauth/strategies/oauth/orkut.rb', line 33

def 
  entry = user_hash['entry']
    {
      'uid' => entry['id'],
      'first_name' => entry['name']['givenName'],
      'last_name' => entry['name']['familyName'],
      'image' => entry['thumbnailUrl']
    }
end