Class: OmniAuth::Strategies::Dailymile

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

Overview

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

Examples:

Basic Usage

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

Returns a new instance of Dailymile.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • client_id (String) (defaults to: nil)

    the application id as registered on Dailymile

  • cliend_secret (String)

    the application secret as registered on Dailymile



15
16
17
18
19
20
21
# File 'lib/omniauth/strategies/oauth2/dailymile.rb', line 15

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

Instance Method Details

#auth_hashObject



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

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

#callback_phaseObject



44
45
46
47
# File 'lib/omniauth/strategies/oauth2/dailymile.rb', line 44

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

#request_phaseObject



39
40
41
42
# File 'lib/omniauth/strategies/oauth2/dailymile.rb', line 39

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

#user_dataObject



35
36
37
# File 'lib/omniauth/strategies/oauth2/dailymile.rb', line 35

def user_data
  @data ||= MultiJson.decode(@access_token.get('/people/me.json'))
end

#user_infoObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/omniauth/strategies/oauth2/dailymile.rb', line 49

def 
  {
    'name' => user_data['display_name'],
    'nickname' => user_data['username'],
    'location' => user_data['location'],
    'image' => user_data['photo_url'],
    'description' => user_data['goal'],
    'urls' => {
      'dailymile' => user_data['url'],
    },
  }
end