Sha256: e41d1f6a32a9e38ed65079eef0653f09e13ac64b1d3de60aa1097fc7af731047

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to Miso via OAuth and retrieve basic
    # user information.
    #
    # Usage:
    #
    #    use OmniAuth::Strategies::Miso, 'consumerkey', 'consumersecret'
    #
    class Miso < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        super(app, :miso, consumer_key, consumer_secret, {:site => 'https://gomiso.com'}, options)
      end

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

      def user_info
        {
          'nickname' => user_hash['username'],
          'name' => user_hash['full_name'],
          'image' => user_hash['profile_image_url'],
          'description' => user_hash['tagline'],
        }
      end

      def user_hash
        @user_hash ||= MultiJson.decode(@access_token.get('/api/oauth/v1/users/show.json').body)['user']
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
omniauth-0.2.6 oa-oauth/lib/omniauth/strategies/miso.rb
oa-oauth-0.2.6 lib/omniauth/strategies/miso.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/miso.rb
oa-oauth-0.2.5 lib/omniauth/strategies/miso.rb