Sha256: c1fda43642185c2af8622dd883145c22ed7e63d14009cda6a2560f6ae3dc1480

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require 'omniauth/strategies/oauth2'

module OmniAuth
  module Strategies
    class Mendeley < OmniAuth::Strategies::OAuth2

      # http://dev.mendeley.com/html/authentication.html
      # Mendeley currently supports only 'all' value
      DEFAULT_SCOPE = 'all'

      option :name, 'mendeley'

      option :client_options, {
        :site           => 'https://mix.mendeley.com',
        :token_path     => '/oauth/token/',
        :authorize_path => '/oauth/authorize/',
      }

      uid do
        raw_info['id']
      end

      info do
        {
          :name       => raw_info['display_name'],
          :first_name => raw_info['first_name'],
          :last_name  => raw_info['last_name'],
          :email      => raw_info['email'],
          :image      => raw_info['photo']['standard'],
          :urls       => {
            'mendeley' => raw_info['link']
          }
        }
      end

      extra do
        {
          'raw_info' => raw_info
        }
      end

      def raw_info
        @raw_info ||= MultiJson.decode(access_token.get('/profiles/me').body)
      end


      def authorize_params
        super.tap do |params|
          params[:scope] ||= DEFAULT_SCOPE
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-mendeley_oauth2-1.0.1 lib/omniauth/strategies/mendeley.rb
omniauth-mendeley_oauth2-1.0 lib/omniauth/strategies/mendeley.rb