Skip to content

Commit

Permalink
Ability to use OAuth 2.0 access token instead of
Browse files Browse the repository at this point in the history
just the API token
  • Loading branch information
sarmad90 committed May 11, 2020
1 parent 5670f09 commit f07f09f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/oktakit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ class Client
builder.adapter Faraday.default_adapter
end

def initialize(token:, organization: nil, api_endpoint: nil)
def initialize(token: nil, access_token: nil, organization: nil, api_endpoint: nil)
if organization.nil? && api_endpoint.nil?
raise ArgumentError, "Please provide either the organization or the api_endpoint argument"
end

if token.blank? && access_token.blank?
raise ArgumentError, "Please provide either the token or the access_token argument"
end

@token = token
@access_token = access_token
@organization = organization
@api_endpoint = api_endpoint
end
Expand Down Expand Up @@ -182,7 +187,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
http.authorization 'SSWS ', @token if @token
http.authorization :Bearer, @access_token if @access_token
end
end

Expand All @@ -195,7 +201,7 @@ def sawyer_options

def absolute_to_relative_url(next_ref)
return unless next_ref

next_ref.href.sub(api_endpoint, '')
end
end
Expand Down

0 comments on commit f07f09f

Please sign in to comment.