Class: Sorcery::Providers::Liveid

Inherits:
Base
  • Object
show all
Includes:
Sorcery::Protocols::Oauth2
Defined in:
lib/sorcery/providers/liveid.rb

Overview

This class adds support for OAuth with microsoft liveid.

config.liveid.key = <key>
config.liveid.secret = <secret>
...

Instance Attribute Summary collapse

Attributes inherited from Base

#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping

Instance Method Summary collapse

Methods included from Sorcery::Protocols::Oauth2

#authorize_url, #build_client, #get_access_token, #oauth_version

Methods inherited from Base

descendants, #has_callback?, name

Constructor Details

#initializeLiveid

Returns a new instance of Liveid.



15
16
17
18
19
20
21
22
23
# File 'lib/sorcery/providers/liveid.rb', line 15

def initialize
  super

  @site           = 'https://oauth.live.com/'
  @auth_url       = '/authorize'
  @token_path     = '/token'
  @user_info_url  = 'https://apis.live.net/v5.0/me'
  @scope          = 'wl.basic wl.emails wl.offline_access'
end

Instance Attribute Details

#auth_urlObject

Returns the value of attribute auth_url.



13
14
15
# File 'lib/sorcery/providers/liveid.rb', line 13

def auth_url
  @auth_url
end

#scopeObject

Returns the value of attribute scope.



13
14
15
# File 'lib/sorcery/providers/liveid.rb', line 13

def scope
  @scope
end

#token_pathObject

Returns the value of attribute token_path.



13
14
15
# File 'lib/sorcery/providers/liveid.rb', line 13

def token_path
  @token_path
end

#user_info_urlObject

Returns the value of attribute user_info_url.



13
14
15
# File 'lib/sorcery/providers/liveid.rb', line 13

def 
  @user_info_url
end

Instance Method Details

#get_user_hash(access_token) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/sorcery/providers/liveid.rb', line 25

def get_user_hash(access_token)
  access_token.token_param = 'access_token'
  response = access_token.get()

  {}.tap do |h|
    h[:user_info] = JSON.parse(response.body)
    h[:uid] = h[:user_info]['id']
  end
end

#login_url(params, session) ⇒ Object

calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.



37
38
39
# File 'lib/sorcery/providers/liveid.rb', line 37

def (params, session)
  self.authorize_url({ authorize_url: auth_url })
end

#process_callback(params, session) ⇒ Object

tries to login the user from access token



42
43
44
45
46
47
48
49
# File 'lib/sorcery/providers/liveid.rb', line 42

def process_callback(params, session)
  args = {}.tap do |a|
    a[:code] = params[:code] if params[:code]
  end

  get_access_token(args, access_token_path: token_path,
    access_token_method: :post)
end