Sha256: 5b1ee34c74d7ae5da59ce2a599b6233c7349d9164732a55a5372c32d95356706

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    class Ourkudos < OAuth2

      include OmniAuth::Strategy
      def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)      
        super app, :ourkudos, client_id, client_secret, {:site => 'http://localhost:3000'}, options, &block
      end

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

      def user_data
       @data ||= MultiJson.decode(@access_token.get(client.site + '/oauth/user', {'oauth_token' => @access_token.token}))
      end

      def user_info
        {
          'email'      => (user_data["email"] if user_data["email"]),
          'first_name' => user_data["first_name"],
          'last_name'  => user_data["last_name"],
          'name'       => "#{user_data['first_name']} #{user_data['last_name']}"
        }
      end

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

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ourkudos-0.0.38 lib/ourkudos/strategies/strategy.rb
ourkudos-0.0.37 lib/ourkudos/strategies/strategy.rb
ourkudos-0.0.34 lib/ourkudos/strategies/strategy.rb
ourkudos-0.0.33 lib/ourkudos/strategies/strategy.rb
ourkudos-0.0.31 lib/ourkudos/strategies/strategy.rb
ourkudos-0.0.30 lib/ourkudos/strategies/strategy.rb