~ubuntu-branches/debian/experimental/ruby-omniauth-authentiq/experimental

« back to all changes in this revision

Viewing changes to lib/omniauth/strategies/authentiq.rb

  • Committer: Package Import Robot
  • Author(s): Pirate Praveen
  • Date: 2017-01-27 16:33:42 UTC
  • Revision ID: package-import@ubuntu.com-20170127163342-volw85ps3ghi2394
Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'omniauth-oauth2'
 
2
 
 
3
module OmniAuth
 
4
  module Strategies
 
5
    class Authentiq < OmniAuth::Strategies::OAuth2
 
6
      #Set the base URL
 
7
      BASE_URL = 'https://connect.authentiq.io/'
 
8
 
 
9
      # Authentiq strategy name
 
10
      option :name, 'authentiq'
 
11
 
 
12
      # Build the basic client options (url, authorization url, token url)
 
13
      option :client_options, {
 
14
          :site => BASE_URL,
 
15
          :authorize_url => '/authorize',
 
16
          :token_url => '/token'
 
17
      }
 
18
 
 
19
      # Get options from parameters
 
20
      option :authorize_options, [:scope, :display]
 
21
 
 
22
      # These are called after authentication has succeeded. If
 
23
      # possible, you should try to set the UID without making
 
24
      # additional calls (if the user id is returned with the token
 
25
      # or as a URI parameter). This may not be possible with all
 
26
      # providers.
 
27
 
 
28
      # Get the user id from raw info
 
29
      uid { raw_info['sub'] }
 
30
 
 
31
      info do
 
32
        {
 
33
            :name => (@raw_info['name'] unless @raw_info['name'].nil?),
 
34
            :first_name => (@raw_info['given_name'] unless @raw_info['given_name'].nil?),
 
35
            :last_name => (@raw_info['family_name'] unless @raw_info['family_name'].nil?),
 
36
            :email => (@raw_info['email'] unless @raw_info['email'].nil?),
 
37
            :phone => (@raw_info['phone_number'] unless @raw_info['phone_number'].nil?),
 
38
            :location => (@raw_info['address'] unless @raw_info['address'].nil?),
 
39
            :geolocation => (@raw_info['aq:location'] unless @raw_info['aq:location'].nil?)
 
40
        }.reject { |k, v| v.nil? }
 
41
      end
 
42
 
 
43
      extra do
 
44
        {
 
45
            :middle_name => (@raw_info['middle_name'] unless @raw_info['middle_name'].nil?),
 
46
            :email_verified => (@raw_info['email_verified'] unless @raw_info['email_verified'].nil?),
 
47
            :phone_type => (@raw_info['phone_type'] unless @raw_info['phone_type'].nil?),
 
48
            :phone_number_verified => (@raw_info['phone_number_verified'] unless @raw_info['phone_number_verified'].nil?),
 
49
            :locale => (@raw_info['locale'] unless @raw_info['locale'].nil?),
 
50
            :zoneinfo => (@raw_info['zoneinfo'] unless @raw_info['zoneinfo'].nil?)
 
51
        }.reject { |k, v| v.nil? }
 
52
      end
 
53
 
 
54
      def raw_info
 
55
        @raw_info ||= access_token.get('/userinfo').parsed
 
56
      end
 
57
 
 
58
      # Over-ride callback_url definition to maintain
 
59
      # compatibility with omniauth-oauth2 >= 1.4.0
 
60
      #
 
61
      # See: https://github.com/intridea/omniauth-oauth2/issues/81
 
62
      def callback_url
 
63
        # Fixes regression in omniauth-oauth2 v1.4.0 by https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7
 
64
        options[:callback_url] || (full_host + script_name + callback_path)
 
65
      end
 
66
    end
 
67
  end
 
68
end