Class: HubIdentityRuby::Server

Inherits:
Object
  • Object
show all
Defined in:
app/models/hub_identity_ruby/server.rb

Constant Summary collapse

HUBIDENTITY_BASE_URL =
"https://stage-identity.hubsynch.com"

Class Method Summary collapse

Class Method Details

.certsObject



5
6
7
8
9
# File 'app/models/hub_identity_ruby/server.rb', line 5

def self.certs
  # response = Faraday.get "#{hostname}/api/v1/oauth/certs"
  response = Excon.get("#{hostname}/api/v1/oauth/certs")
  JSON.parse(response.body, symbolize_names: true)
end

.get_cert(key_id) ⇒ Object



11
12
13
# File 'app/models/hub_identity_ruby/server.rb', line 11

def self.get_cert(key_id)
  certs.find {|key| key[:kid] == key_id}
end

.get_current_user(user_token) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/hub_identity_ruby/server.rb', line 15

def self.get_current_user(user_token)
  if user_token.present?
    url = "#{hostname}/api/v1/current_user/#{user_token}"
    response = Excon.get(url, :headers => {'x-api-key' => private_api_key})
    # response = Faraday.get(url) do |req|
    #   req.headers['x-api-key'] = private_api_key
    # end

    if response.status == 200
      CurrentUser.new(response.body).hash
    else
      nil
    end
  end
end

.hostnameObject



31
32
33
# File 'app/models/hub_identity_ruby/server.rb', line 31

def self.hostname
  ENV['HUBIDENTITY_URL'] || HUBIDENTITY_BASE_URL
end