Class: OmniAuth::Strategies::TypePad
- Defined in:
- lib/omniauth/strategies/oauth/type_pad.rb
Overview
Authenticate to Typepad via OAuth and retrieve basic user information.
Usage: use OmniAuth::Strategies::Typepad, 'consumerkey', 'consumersecret', :application_id => 'my_type_pad_application_id' application_id is required.
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ TypePad
constructor
A new instance of TypePad.
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ TypePad
Returns a new instance of TypePad.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/omniauth/strategies/oauth/type_pad.rb', line 13 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) # TypePad uses the application ID for one of the OAuth paths. app_id = [:application_id] = { :access_token_path => '/secure/services/oauth/access_token', :authorize_path => "/secure/services/api/#{app_id}/oauth-approve", :http_method => :get, # You *must* use query_string for the token dance. :scheme => :query_string, :site => 'https://www.typepad.com', :request_token_path => '/secure/services/oauth/request_token', } .merge! :scheme => :query_string, :http_method => :get super(app, :type_pad, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/omniauth/strategies/oauth/type_pad.rb', line 29 def auth_hash ui = user_info OmniAuth::Utils.deep_merge( super, { 'uid' => ui['uid'], 'user_info' => ui, 'extra' => { 'user_hash' => user_hash, }, } ) end |
#user_hash ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/omniauth/strategies/oauth/type_pad.rb', line 56 def user_hash # For authenticated requests, you have to use header as your scheme. # Failure to do so gives a unique response body - 'Auth is required'. # 'Unauthorized' is the response body of a truly unauthorized request. # Also note that API requests hit a different site than the OAuth dance. r = self.consumer.request(:get, 'https://api.typepad.com/users/@self.json', @access_token, :scheme => 'header') @user_hash ||= MultiJson.decode(r.body) end |
#user_info ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/omniauth/strategies/oauth/type_pad.rb', line 42 def user_info user_hash = self.user_hash { 'uid' => user_hash['urlId'], 'nickname' => user_hash['preferredUsername'], 'name' => user_hash['displayName'], 'image' => user_hash['avatarLink']['url'], 'description' => user_hash['aboutMe'], 'urls' => { 'Profile' => user_hash['profilePageUrl'], }, } end |