Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth servers #58

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/oktakit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'oktakit/response/raise_error'
require 'oktakit/client/admin_roles'
require 'oktakit/client/apps'
require 'oktakit/client/authorization_servers'
require 'oktakit/client/events'
require 'oktakit/client/factors'
require 'oktakit/client/groups'
Expand All @@ -15,6 +16,7 @@ module Oktakit
class Client
include AdminRoles
include Apps
include AuthorizationServers
include Events
include Factors
include Groups
Expand Down Expand Up @@ -189,8 +191,8 @@ def sawyer_agent
http.headers[:accept] = 'application/json'
http.headers[:content_type] = 'application/json'
http.headers[:user_agent] = "Oktakit v#{Oktakit::VERSION}"
http.authorization('SSWS ', @token) if @token
http.authorization(:Bearer, @access_token) if @access_token
http.headers[:authorization] = "SSWS #{@token}" if @token
http.headers[:authorization] = "Bearer #{@access_token}" if @access_token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking, why is this change needed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure why specifically this change was made but if I had to guess it was likely to make the application of the authorization header uniform with the how the other headers were being set above it. If this is a blocker we can likely revert this change without issue.

end
end

Expand Down
164 changes: 164 additions & 0 deletions lib/oktakit/client/authorization_servers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
module Oktakit
class Client
module AuthorizationServers
# Add Authorization Server
#
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] The created Authorization Server
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#create-authorization-server
# @example
# Oktakit.add_authorization_server
def add_authorization_server(options = {})
post("/authorizationServers", options)
end

# Get Authorization Server
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Fetched Authorization Server
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#get-authorization-server
# @example
# Oktakit.get_authorization_server('id')
def get_authorization_server(id, options = {})
get("/authorizationServers/#{id}", options)
end

# List Authorization Servers
#
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Array of Authorization Servers
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#list-authorization-servers
# @example
# Oktakit.list_authorization_servers
def list_authorization_servers(options = {})
get("/authorizationServers", options)
end

# List Authorization Server Policies
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Array of Authorization Server Policies
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#get-all-policies
# @example
# Oktakit.list_authorization_server_policies('id')
def list_authorization_server_policies(id, options = {})
get("/authorizationServers/#{id}/policies", options)
end

# Add Authorization Server Policy
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] The Created Authorization Server Policy
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#create-a-policy
# @example
# Oktakit.add_authorization_server_policy('id')
def add_authorization_server_policy(id, options = {})
post("/authorizationServers/#{id}/policies", options)
end

# Update Authorization Server
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Updated Authorization Server
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#update-authorization-server
# @example
# Oktakit.update_authorization_server('id')
def update_authorization_server(id, options = {})
put("/authorizationServers/#{id}", options)
end

# Update Authorization Server Policy
#
# @params id [string] Authorization Server ID
# @params policy_id [string] Authorization Server Policy ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Updated Authorization Server Policy
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#update-a-policy
# @example
# Oktakit.update_authorization_server_policy('id', 'policy_id')
def update_authorization_server_policy(id, policy_id, options = {})
put("/authorizationServers/#{id}/policies/#{policy_id}", options)
end

# Delete Authorization Server
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] HTTP 204 No Content
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#delete-authorization-server
# @example
# Oktakit.delete_authorization_server('id)
def delete_authorization_server(id, options = {})
delete("/authorizationServers/#{id}", options)
end

# Activate Authorization Server
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] HTTP 204 No Content
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#activate-authorization-server
# @example
# Oktakit.activate_authorization_server('id')
def activate_authorization_server(id, options = {})
post("/authorizationServers/#{id}/lifecycle/activate")
end

# Deactivate Authorization Server
#
# @params id [string] Authorization Server ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] HTTP 204 No Content
# @see https://developer.okta.com/docs/reference/api/authorization-servers/#deactivate-authorization-server
# @example
# Oktakit.deactivate_authorization_server('id')
def deactivate_authorization_server(id, options = {})
post("/authorizationServers/#{id}/lifecycle/deactivate")
end
end
end
end
61 changes: 61 additions & 0 deletions spec/cassettes/activate_authorization_server.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/cassettes/add_authorization_server.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions spec/cassettes/add_authorization_server_policy.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading