Sha256: 42aace9289080cdd0e430906cd936ad45fd9e2aaf105d9e1d614fb09d31ba946

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class G5 < OmniAuth::Strategies::OAuth2
      option :name, :g5

      option :client_options, {
        :site => 'https://auth.g5search.com',
        :authorize_url => '/oauth/authorize',
        :token_url => '/oauth/token'
      }

      uid { raw_info['id'] }

      info do
        {:email => raw_info['email'],
         :name => display_name,
         :first_name => raw_info['first_name'],
         :last_name => raw_info['last_name'],
         :phone => raw_info['phone_number']}
      end

      extra do
        {:raw_info => raw_info,
         :title => raw_info['title'],
         :organization_name => raw_info['organization_name'],
         :roles => roles}
      end

      def raw_info
        @raw_info ||= access_token.get('/v1/me.json').parsed
      end

      def display_name
        "#{raw_info['first_name']} #{raw_info['last_name']}".strip
      end

      def roles
        [raw_info['roles']].flatten.collect do |role|
          {:name => role['name']}
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-g5-0.2.0 lib/omniauth/strategies/g5.rb