Sha256: 629bc76960d6c3575e7ed9b69e41dec27a930904b17ca9404fb9030348932f59

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to SmugMug via OAuth and retrieve basic user information.
    # Usage:
    #    use OmniAuth::Strategies::SmugMug, 'consumerkey', 'consumersecret'
    #
    class SmugMug < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        super(app, :smugmug, consumer_key, consumer_secret,
                {:site               => 'http://api.smugmug.com',
                :request_token_path => "/services/oauth/getRequestToken.mg",
                :access_token_path  => "/services/oauth/getAccessToken.mg",
                :authorize_path     => "/services/oauth/authorize.mg"}, options, &block)
      end
      
      def auth_hash
        OmniAuth::Utils.deep_merge(super, {
          'uid' => user_hash['id'],
          'user_info' => user_info,
          'extra' => { 'user_hash' => user_hash }
        })
      end
      
      # user info according to schema
      def user_info
        { 
          'nickname' => user_hash['NickName'],
          'name' => user_hash['NickName']
        }
      end
      
      # info as supplied by SmugMug
      def user_hash
        @user_hash ||= MultiJson.decode(@access_token.get('/services/api/json/1.2.2/?method=smugmug.auth.checkAccessToken').body)['Auth']['User']
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
oa-oauth-0.2.4 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.3 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.2 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.1 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0.beta5 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0.beta4 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0.beta3 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0.beta2 lib/omniauth/strategies/smug_mug.rb
oa-oauth-0.2.0.beta1 lib/omniauth/strategies/smug_mug.rb