Class: OmniAuth::Strategies::Doit

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

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) ⇒ Doit



7
8
9
10
11
12
13
# File 'lib/omniauth/strategies/oauth2/doit.rb', line 7

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://openapi.doit.im/oauth/authorize',
    :token_url => 'https://openapi.doit.im/oauth/access_token',
  }
  super(app, :doit, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/omniauth/strategies/oauth2/doit.rb', line 15

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

#callback_phaseObject



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

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

#request_phaseObject



31
32
33
34
# File 'lib/omniauth/strategies/oauth2/doit.rb', line 31

def request_phase
  options[:response_type] ||= 'code'
  super
end

#user_dataObject



27
28
29
# File 'lib/omniauth/strategies/oauth2/doit.rb', line 27

def user_data
  @data ||= MultiJson.decode(@access_token.get('https://openapi.doit.im/v1/settings'), {'Authorization' => 'OAuth' + @access_token.token})
end

#user_infoObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/omniauth/strategies/oauth2/doit.rb', line 41

def 
  {
    'account' => user_data['account'],
    'username'=> user_data['username'],
    'nickname'=> user_data['nickname'],
    'gender'=> user_data['gender'],
    'week_start'=> user_data['week_start'],
    'birthday_day'=> user_data['birthday_day'],
    'birthday_month'=> user_data['birthday_month'],
    'birthday_year'=> user_data['birthday_year'],
    'language'=> user_data['language'],
    'user_timezone'=> user_data['user_timezone'],
    'remind_email'=> user_data['remind_email'],
    'created'=> user_data['created'],
    'updated'=> user_data['updated'],
  }
end