Class: OmniAuth::Strategies::Liveid

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

Overview

Authenticate to Windows Connect utilizing OAuth 2.0 and retrieve basic user information.

OAuth 2.0 - MS Documentation http://msdn.microsoft.com/en-us/library/hh243647.aspx

Sign-up for account: http://go.microsoft.com/fwlink/?LinkId=213332

Examples:

Basic Usage of Liveid


use OmniAuth::Strategies::Liveid, 'client_id', 'client_secret'

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Liveid

Returns a new instance of Liveid.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :scope (String)

    separate the scopes by a space



20
21
22
23
24
25
26
27
# File 'lib/omniauth/strategies/oauth2/liveid.rb', line 20

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://oauth.live.com/authorize',
    :token_url => 'https://oauth.live.com/token'
  }
  
  super(app, :liveid, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/omniauth/strategies/oauth2/liveid.rb', line 29

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

#request_phaseObject



42
43
44
45
46
# File 'lib/omniauth/strategies/oauth2/liveid.rb', line 42

def request_phase
  options[:scope] ||= 'wl.signin wl.basic'
  options[:response_type] ||= 'code'
  super
end

#user_dataObject



48
49
50
# File 'lib/omniauth/strategies/oauth2/liveid.rb', line 48

def user_data
  @data ||= MultiJson.decode(@access_token.get('https://apis.live.net/v5.0/me').body)
end

#user_infoObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/omniauth/strategies/oauth2/liveid.rb', line 52

def 
  {
    'id' => user_data['id'],
    'name' => user_data['name'],
    'email' => '',
    'first_name' => user_data['first_name'],
    'last_name' => user_data['last_name'],
    'link' => user_data['link'],
    'gender' => user_data['gender'],
    'locale' => user_data['locale']                    
  }
end