Class: OmniAuth::Strategies::Tumblr

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/tumblr.rb

Overview

Authenticate to Tumblr via OAuth and retrieve basic user information.

Usage:

use OmniAuth::Strategies::Tumblr, 'consumerkey', 'consumersecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tumblr

Initialize the middleware

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :sign_in (Boolean, true)

    When true, use the "Sign in with Tumblr" flow instead of the authorization flow.



17
18
19
20
21
22
23
24
# File 'lib/omniauth/strategies/tumblr.rb', line 17

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  client_options = {
    :site => 'http://www.tumblr.com'
  }

  client_options[:authorize_path] = '/oauth/authorize' unless options[:sign_in] == false
  super(app, :tumblr, consumer_key, consumer_secret, client_options, options)
end

Instance Method Details

#auth_hashObject



26
27
28
29
30
31
32
# File 'lib/omniauth/strategies/tumblr.rb', line 26

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

#userObject



45
46
47
48
49
50
51
52
# File 'lib/omniauth/strategies/tumblr.rb', line 45

def user
  tumblelogs = user_hash['tumblr']['tumblelog']
  if tumblelogs.kind_of?(Array)
    @user ||= tumblelogs[0]
  else
    @user ||= tumblelogs
  end
end

#user_hashObject



54
55
56
57
# File 'lib/omniauth/strategies/tumblr.rb', line 54

def user_hash
  url = "http://www.tumblr.com/api/authenticate"
  @user_hash ||= Hash.from_xml(@access_token.get(url).body)
end

#user_infoObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/omniauth/strategies/tumblr.rb', line 34

def 
  {
    'nickname' => user['name'],
    'name' => user['title'],
    'image' => user['avatar_url'],
    'urls' => {
      'website' => user['url'],
    }
  }
end