Class: Okta::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/okta/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.okta'
API_BASE_PATH =
'/api/v1'
USER_API_BASE_PATH =
"#{API_BASE_PATH}/users".freeze
APP_API_BASE_PATH =
"#{API_BASE_PATH}/apps".freeze
AUTH_SERVER_API_BASE_PATH =
"#{API_BASE_PATH}/authorizationServers".freeze

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#with_monitoring

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Instance Method Details

#app(app_id) ⇒ Object



29
30
31
32
33
# File 'lib/okta/service.rb', line 29

def app(app_id)
  with_monitoring do
    get_url_with_token("#{APP_API_BASE_PATH}/#{app_id}")
  end
end

#auth_server(auth_server_id) ⇒ Object



35
36
37
38
39
# File 'lib/okta/service.rb', line 35

def auth_server(auth_server_id)
  with_monitoring do
    get_url_with_token("#{AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}")
  end
end

#auth_serversObject



41
42
43
44
45
# File 'lib/okta/service.rb', line 41

def auth_servers
  with_monitoring do
    get_url_with_token(AUTH_SERVER_API_BASE_PATH)
  end
end

#call_with_token(action, url) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/okta/service.rb', line 20

def call_with_token(action, url)
  connection.send(action) do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.headers['Accept'] = 'application/json'
    req.headers['Authorization'] = "SSWS #{Settings.oidc.base_api_token}"
  end
end

#delete_grant(user_id, grant_id) ⇒ Object



71
72
73
74
75
# File 'lib/okta/service.rb', line 71

def delete_grant(user_id, grant_id)
  with_monitoring do
    delete_url_with_token("#{USER_API_BASE_PATH}/#{user_id}/grants/#{grant_id}")
  end
end

#get_server_scopes(server_id) ⇒ Object



47
48
49
50
51
# File 'lib/okta/service.rb', line 47

def get_server_scopes(server_id)
  with_monitoring do
    get_url_with_token("#{AUTH_SERVER_API_BASE_PATH}/#{server_id}/scopes")
  end
end

#grants(user_id) ⇒ Object



65
66
67
68
69
# File 'lib/okta/service.rb', line 65

def grants(user_id)
  with_monitoring do
    get_url_with_token("#{USER_API_BASE_PATH}/#{user_id}/grants")
  end
end

#metadata(iss) ⇒ Object



83
84
85
86
87
88
# File 'lib/okta/service.rb', line 83

def (iss)
  proxied_iss = iss.gsub(Settings.oidc.issuer_prefix, "#{Settings.oidc.base_api_url}oauth2")
  with_monitoring do
    get_url_no_token("#{proxied_iss}/.well-known/openid-configuration")
  end
end

#system_logs(event, time) ⇒ Object



77
78
79
80
81
# File 'lib/okta/service.rb', line 77

def system_logs(event, time)
  with_monitoring do
    get_url_with_token("#{API_BASE_PATH}/logs?filter=eventType+eq+%22#{event}%22&since=#{time}")
  end
end

#user(user_id) ⇒ Object



53
54
55
56
57
# File 'lib/okta/service.rb', line 53

def user(user_id)
  with_monitoring do
    get_url_with_token("#{USER_API_BASE_PATH}/#{user_id}")
  end
end

#user_search_by_icn(icn) ⇒ Object



59
60
61
62
63
# File 'lib/okta/service.rb', line 59

def user_search_by_icn(icn)
  with_monitoring do
    get_url_with_token("#{USER_API_BASE_PATH}?search=profile.lighthouseId+eq+%22#{icn}%22")
  end
end