Sha256: bdd9b1d4aa8e87b3a91c0656057d9e82b52ebeea6554be3258d9a5d01bc2c154

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    class Doit < OAuth2
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        client_options = {
          :site => 'https://openapi.doit.im',
          :authorize_url => 'https://openapi.doit.im/oauth/authorize',
          :access_token_url => 'https://openapi.doit.im/oauth/access_token'
        }

        super(app, :doit, consumer_key, consumer_secret, client_options, options, &block)
      end

      protected

      def user_data
        @data ||= MultiJson.decode(@access_token.get(client.site+"/v1/settings"),{'Authorization'=> 'OAuth'+@access_token.token})
      end

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

      def callback_phase
        options[:grant_type] ||= 'authorization_code'
        super
      end

      def user_info
        {
          'account' => user_data['account'],
          'username'=> user_data['username'],
          'nickname'=> user_data['nickname'],
          'gender'=> user_data['gender'],
          'week_start'=> user_data['week_start'],
          'birthday_day'=> user_data['birthday_day'],
          'birthday_month'=> user_data['birthday_month'],
          'birthday_year'=> user_data['birthday_year'],
          'language'=> user_data['language'],
          'user_timezone'=> user_data['user_timezone'],
          'remind_email'=> user_data['remind_email'],
          'created'=> user_data['created'],
          'updated'=> user_data['updated']
        }
      end

      def auth_hash
        OmniAuth::Utils.deep_merge(super, {
          'uid' => user_data['id'],
          'user_info' => user_info,
          'extra' => {'user_hash' => user_data}
        })
      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/doit.rb
oa-oauth-0.2.6 lib/omniauth/strategies/doit.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/doit.rb
oa-oauth-0.2.5 lib/omniauth/strategies/doit.rb