Class: OmniAuth::Strategies::ServiceNow

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/service_now.rb

Constant Summary collapse

SITE_REGEXP =
/(?:https:\/\/)?(?:([^.]+)\.)?service-now\.com/

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



27
28
29
30
31
32
33
34
35
# File 'lib/omniauth/strategies/service_now.rb', line 27

def authorize_params
  super.tap do |params|
    %w[client_options].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
      end
    end
  end
end

#build_access_tokenObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/omniauth/strategies/service_now.rb', line 37

def build_access_token
  verifier = request.params["code"]
  # Override regular client when using setup: proc
  if env['omniauth.params']['client_id'] && env['omniauth.params']['client_secret'] && env['omniauth.params']['site']
    client = ::OAuth2::Client.new(
      env['omniauth.params']['client_id'],
      env['omniauth.params']['client_secret'],
      site: env['omniauth.params']['site'],
      authorize_url: options.client_options.authorize_url,
      token_url: options.client_options.token_url
    )
    client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
  else
    super
  end
end

#callback_urlObject



80
81
82
# File 'lib/omniauth/strategies/service_now.rb', line 80

def callback_url
  full_host + script_name + callback_path
end

#instance_idObject



76
77
78
# File 'lib/omniauth/strategies/service_now.rb', line 76

def instance_id
  @instance_id ||= smart_site.match(SITE_REGEXP)[1] if smart_site
end

#raw_infoObject



60
61
62
# File 'lib/omniauth/strategies/service_now.rb', line 60

def raw_info
  @raw_info ||= options[:extra_client_id_and_client_secret] ? { client_id: smart_client_id, client_secret: smart_client_secret } : {}
end

#smart_client_idObject



64
65
66
# File 'lib/omniauth/strategies/service_now.rb', line 64

def smart_client_id
  @smart_client_id ||= env['omniauth.params']['client_id'] || env['omniauth.strategy'].options.client_id
end

#smart_client_secretObject



68
69
70
# File 'lib/omniauth/strategies/service_now.rb', line 68

def smart_client_secret
  @smart_client_secret ||= env['omniauth.params']['client_secret'] || env['omniauth.strategy'].options.client_secret
end

#smart_siteObject



72
73
74
# File 'lib/omniauth/strategies/service_now.rb', line 72

def smart_site
  @site ||= env['omniauth.params']['site'] || env['omniauth.strategy'].options.site || options.client_options.site
end