Class: OmniAuth::Strategies::Mixi

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

Overview

Authenticate to Facebook utilizing OAuth 2.0 and retrieve basic user information.

Examples:

Basic Usage

use OmniAuth::Strategies::Mixi, '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) ⇒ Mixi

Returns a new instance of Mixi.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :scope (String)

    separate the scopes by a space



13
14
15
16
17
18
19
# File 'lib/omniauth/strategies/oauth2/mixi.rb', line 13

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://mixi.jp/connect_authorize.pl',
    :token_url => 'https://secure.mixi-platform.com/2/token',
  }
  super(app, :mixi, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omniauth/strategies/oauth2/mixi.rb', line 21

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

#callback_phaseObject



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

def callback_phase
  options[:grant_type] ||= 'authorization_code'
  super
end

#request_phaseObject



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

def request_phase
  options[:scope] ||= 'r_profile'
  options[:display] ||= 'pc'
  options[:response_type] ||= 'code'
  super
end

#user_dataObject



34
35
36
37
38
39
# File 'lib/omniauth/strategies/oauth2/mixi.rb', line 34

def user_data
  @data ||= MultiJson.decode(@access_token.get(
    'http://api.mixi-platform.com/2/people/@me/@self',
    {'oauth_token' => @access_token.token}
  ))
end

#user_infoObject



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

def 
  {
    'nickname' => user_data['entry']['displayName'],
    'image' => user_data['entry']['thumbnailUrl'],
    'urls' => {
      :profile => user_data['entry']['profileUrl'],
    },
  }
end