class Simpleokta::Client

Attributes

api_token[RW]
base_api_url[RW]

Public Class Methods

new(config) click to toggle source

Initialize using passed in config hash @param config [Hash]

# File lib/simpleokta/client.rb, line 24
def initialize(config)
  @api_token = config[:api_token]
  @base_api_url = config[:base_api_url]
  @http ||= HTTP::Client.new
end

Public Instance Methods

call_with_token(action, url, body = {}) click to toggle source

This method will add our api_token to each authorization header to keep our code D.R.Y @param action [String] the HTTP verb we are sending our request with.

IE: 'get', 'post', 'put', 'delete'

@param url [String] the URL to send the request to. @param body [Hash] the request body, set to an empty hash by default.

Each request may require a different body schema.
# File lib/simpleokta/client.rb, line 36
def call_with_token(action, url, body = {})
  uri = @base_api_url + url
  @http
    .headers(accept: 'application/json', content: 'application/json')
    .auth("SSWS #{@api_token}")
    .send(action, uri, { json: body })
end
claim(auth_server_id, claim_id) click to toggle source

Get a specific Claim defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param claim_id [String] the unique id of the claim @return [Hash<Claim Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#claim-object Claim Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-a-claim Get Claim

# File lib/simpleokta/auth_servers.rb, line 338
def claim(auth_server_id, claim_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/claims/#{claim_id}"
  )
  JSON.parse(response.body)
end
claims(auth_server_id) click to toggle source

Get all Claims defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @return [Array<Claim Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#claim-object Claim Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-all-claims Get Claims

# File lib/simpleokta/auth_servers.rb, line 324
def claims(auth_server_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/claims"
  )
  JSON.parse(response.body)
end
client_resources(auth_server_id) click to toggle source

Lists all Client Resources for which the specified Authorization Server has tokens @param auth_server_id [String] the unique id of the authorization server @return [Array<Hash>] @see developer.okta.com/docs/reference/api/authorization-servers/#list-client-resources-for-an-authorization-server List Client Resources for an Authorization Server

# File lib/simpleokta/auth_servers.rb, line 425
def client_resources(auth_server_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/clients"
  )
  JSON.parse(response.body)
end
create_claim(auth_server_id, claim_data) click to toggle source

Create a Claim for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param claim_data [Hash<Claim_Object>] the data of the claim you wish to create @return [Hash<Claim Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#claim-object Claim Object @see developer.okta.com/docs/reference/api/authorization-servers/#create-a-claim Create Claim

# File lib/simpleokta/auth_servers.rb, line 352
def create_claim(auth_server_id, claim_data)
  response = call_with_token(
    'post',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/claims",
    claim_data
  )
  JSON.parse(response.body)
end
create_rule(auth_server_id, policy_id, rule_data) click to toggle source

Create a Policy Rule for a given Policy on a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param policy_id [String] the unique id of the policy @param rule_data [Hash] the rule object you want to create @return [Hash<Rule Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#rule-object Rule object @see developer.okta.com/docs/reference/api/authorization-servers/#create-a-policy-rule Create Policy Rule

# File lib/simpleokta/auth_servers.rb, line 204
def create_rule(auth_server_id, policy_id, rule_data)
  response = call_with_token(
    'post',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/policies/#{policy_id}/rules",
    rule_data
  )
  JSON.parse(response.body)
end
create_scope(auth_server_id, scope_data) click to toggle source

Create a Scope for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param scope_data [Hash<Scope Object>] the data of the scope you wish to create @return [Hash<Scope Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#scope-object Scope Object @see developer.okta.com/docs/reference/api/authorization-servers/#create-a-scope Create Scope

# File lib/simpleokta/auth_servers.rb, line 279
def create_scope(auth_server_id, scope_data)
  response = call_with_token(
    'post',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/scopes",
    scope_data
  )
  JSON.parse(response.body)
end
delete_claim(auth_server_id, claim_id) click to toggle source

Delete a specific Claim defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param claim_id [String] the unique id of the claim @return 204 No Content @see developer.okta.com/docs/reference/api/authorization-servers/#claim-object Claim Object @see developer.okta.com/docs/reference/api/authorization-servers/#delete-a-claim Delete Claim

# File lib/simpleokta/auth_servers.rb, line 383
def delete_claim(auth_server_id, claim_id)
  call_with_token(
    'delete',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/claims/#{claim_id}"
  )
end
delete_rule(auth_server_id, policy_id, rule_id) click to toggle source

Delete a Policy Rule for a given Policy on a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param policy_id [String] the unique id of the policy @param rule_id [String] the unique id of the rule @return 204 No Content @see developer.okta.com/docs/reference/api/authorization-servers/#rule-object Rule object @see developer.okta.com/docs/reference/api/authorization-servers/#delete-a-policy-rule Delete Policy Rule

# File lib/simpleokta/auth_servers.rb, line 237
def delete_rule(auth_server_id, policy_id, rule_id)
  call_with_token(
    'delete',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/policies/#{policy_id}/rules/#{rule_id}"
  )
end
delete_scope(auth_server_id, scope_id) click to toggle source

Delete a Scope for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param scope_id [String] the unique id of the scope @return 204 No Content @see developer.okta.com/docs/reference/api/authorization-servers/#scope-object Scope Object @see developer.okta.com/docs/reference/api/authorization-servers/#delete-a-scope Delete Scope

# File lib/simpleokta/auth_servers.rb, line 310
def delete_scope(auth_server_id, scope_id)
  call_with_token(
    'delete',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/scopes/#{scope_id}"
  )
end
keys(auth_server_id) click to toggle source

Get all Keys associated with a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @return [Array<Credentials Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#credentials-object Credentials Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-all-claims Get Authorization Server Keys

# File lib/simpleokta/auth_servers.rb, line 397
def keys(auth_server_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/credentials/keys"
  )
  JSON.parse(response.body)
end
refresh_token(auth_server_id, client_id, token_id) click to toggle source

Gets a specific Refresh Token issued by an Authorization Server for a specific client @param auth_server_id [String] the unique id of the authorization server @param client_id [String] the unique id of the client @param token_id [String] the unique id of the refresh token @return [Array<Hash>] @see developer.okta.com/docs/reference/api/authorization-servers/#get-refresh-token Get Refresh Tokens

# File lib/simpleokta/auth_servers.rb, line 454
def refresh_token(auth_server_id, client_id, token_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/clients/#{client_id}/tokens/#{token_id}"
  )
  JSON.parse(response.body)
end
refresh_tokens(auth_server_id, client_id) click to toggle source

Lists all Refresh Tokens issued by an Authorization Server for a specific client @param auth_server_id [String] the unique id of the authorization server @param client_id [String] the unique id of the client @return [Array<Hash>] @see developer.okta.com/docs/reference/api/authorization-servers/#list-refresh-tokens List Refresh Tokens

# File lib/simpleokta/auth_servers.rb, line 440
def refresh_tokens(auth_server_id, client_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/clients/#{client_id}/tokens"
  )
  JSON.parse(response.body)
end
revoke_refresh_token(auth_server_id, client_id, token_id) click to toggle source

Revokes a specific Refresh Token issued by an Authorization Server for a specific client @param auth_server_id [String] the unique id of the authorization server @param client_id [String] the unique id of the client @param token_id [String] the unique id of the refresh token @return 204 No Content @see developer.okta.com/docs/reference/api/authorization-servers/#revoke-refresh-token Revoke Refresh Token

# File lib/simpleokta/auth_servers.rb, line 481
def revoke_refresh_token(auth_server_id, client_id, token_id)
  response = call_with_token(
    'delete',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/clients/#{client_id}/tokens/#{token_id}"
  )
  JSON.parse(response.body)
end
revoke_refresh_tokens(auth_server_id, client_id) click to toggle source

Revokes all Refresh Tokens issued by an Authorization Server for a specific client @param auth_server_id [String] the unique id of the authorization server @param client_id [String] the unique id of the client @return 204 No Content @see developer.okta.com/docs/reference/api/authorization-servers/#revoke-all-refresh-tokens Revoke Refresh Tokens

# File lib/simpleokta/auth_servers.rb, line 467
def revoke_refresh_tokens(auth_server_id, client_id)
  response = call_with_token(
    'delete',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/clients/#{client_id}/tokens/#{token_id}"
  )
  JSON.parse(response.body)
end
rotate_keys(auth_server_id) click to toggle source

Rotate the current Keys associated with a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @return [Array<Credentials Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#credentials-object Credentials Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-all-claims Rotate Authorization Server Keys

# File lib/simpleokta/auth_servers.rb, line 410
def rotate_keys(auth_server_id)
  response = call_with_token(
    'post',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/credentials/lifecycle/keyRotate",
    { 'use': 'sig' }
  )
  JSON.parse(response.body)
end
rule(auth_server_id, policy_id, rule_id) click to toggle source

Get a specific Policy Rule for a given Policy on a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param policy_id [String] the unique id of the policy @param rule_id [String] the unique id of the rule @return [Hash<Rule Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#rule-object Rule object @see developer.okta.com/docs/reference/api/authorization-servers/#get-a-policy-rule Get Policy Rule

# File lib/simpleokta/auth_servers.rb, line 189
def rule(auth_server_id, policy_id, rule_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/policies/#{policy_id}/rules/#{rule_id}"
  )
  JSON.parse(response.body)
end
rules(auth_server_id, policy_id) click to toggle source

Get all Policy Rules for a given Policy on a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param policy_id [String] the unique id of the policy @return [Array<Rule Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#rule-object Rule object @see developer.okta.com/docs/reference/api/authorization-servers/#get-all-policy-rules Get All Policy Rules

# File lib/simpleokta/auth_servers.rb, line 174
def rules(auth_server_id, policy_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/policies/#{policy_id}/rules"
  )
  JSON.parse(response.body)
end
scope(auth_server_id, scope_id) click to toggle source

Get a specific Scope defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param scope_id [String] the unique id of the scope @return [Hash<Scope Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#scope-object Scope Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-a-scope Get Scopes

# File lib/simpleokta/auth_servers.rb, line 265
def scope(auth_server_id, scope_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/scopes/#{scope_id}"
  )
  JSON.parse(response.body)
end
scopes(auth_server_id) click to toggle source

Get all Scopes defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @return [Array<Scope Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#scope-object Scope Object @see developer.okta.com/docs/reference/api/authorization-servers/#get-all-scopes Get Scopes

# File lib/simpleokta/auth_servers.rb, line 251
def scopes(auth_server_id)
  response = call_with_token(
    'get',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/scopes"
  )
  JSON.parse(response.body)
end
update_claim(auth_server_id, claim_id, claim_data) click to toggle source

Update a specific Claim defined for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param claim_id [String] the unique id of the claim @param claim_data [Hash<Claim_Object>] the data of the claim you wish to create @return [Hash<Claim Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#claim-object Claim Object @see developer.okta.com/docs/reference/api/authorization-servers/#update-a-claim Update Claim

# File lib/simpleokta/auth_servers.rb, line 368
def update_claim(auth_server_id, claim_id, claim_data)
  response = call_with_token(
    'put',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/claims/#{claim_id}",
    claim_data
  )
  JSON.parse(response.body)
end
update_rule(auth_server_id, policy_id, rule_id, rule_data) click to toggle source

Update a Policy Rule for a given Policy on a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param policy_id [String] the unique id of the policy @param rule_id [String] the unique id of the rule @param rule_data [Hash] the rule object you want to update @return [Hash<Rule Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#rule-object Rule object @see developer.okta.com/docs/reference/api/authorization-servers/#update-a-policy-rule Update Policy Rule

# File lib/simpleokta/auth_servers.rb, line 221
def update_rule(auth_server_id, policy_id, rule_id, rule_data)
  response = call_with_token(
    'put',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/policies/#{policy_id}/rules/#{rule_id}",
    rule_data
  )
  JSON.parse(response.body)
end
update_scope(auth_server_id, scope_id, scope_data) click to toggle source

Update a Scope for a given Authorization Server @param auth_server_id [String] the unique id of the authorization server @param scope_id [String] the unique id of the scope @param scope_data [Hash<Scope Object>] the data of the scope you wish to update @return [Hash<Scope Object>] @see developer.okta.com/docs/reference/api/authorization-servers/#scope-object Scope Object @see developer.okta.com/docs/reference/api/authorization-servers/#update-a-scope Create Scope

# File lib/simpleokta/auth_servers.rb, line 295
def update_scope(auth_server_id, scope_id, scope_data)
  response = call_with_token(
    'put',
    "#{Constants::AUTH_SERVER_API_BASE_PATH}/#{auth_server_id}/scopes/#{scope_id}",
    scope_data
  )
  JSON.parse(response.body)
end