Skip to content

Commit

Permalink
Merge pull request Shopify#30 from secureframe/master
Browse files Browse the repository at this point in the history
Added ability to use Okta OAuth 2.0 access token instead of just API token
  • Loading branch information
NickTaylor- authored Aug 25, 2020
2 parents 5670f09 + aec655b commit 9341ba3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 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.nil? && access_token.nil?) || (token && access_token)
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 Down

0 comments on commit 9341ba3

Please sign in to comment.