-
Notifications
You must be signed in to change notification settings - Fork 137
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 Client Credentials grant #129
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a few comments before we chat on this on Friday.
client_secret: @client_secret, | ||
audience: audience | ||
} | ||
post('/oauth/token', request_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of errors can be raised from this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason the request params aren't inlined into the method call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of errors can be raised from this method?
Not totally sure. Is it important to list them? It uses these under the hood:
https://github.com/rest-client/rest-client which uses:
https://ruby-doc.org/stdlib-2.5.1/libdoc/net/http/rdoc/Net/HTTP.html
Any reason the request params aren't inlined into the method call?
None of them except audience
need to be set. Also, just following the example of the rest of the methods here. Would that look like:
def api_token(
client_id: @client_id,
client_secret: @client_secret,
audience: "https://#{@domain}/api/v2/"
)
request_params = {
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret,
audience: audience
}
post('/oauth/token', request_params)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushing that change, would like to go this direction in general and need to start somewhere.
client_secret: client_secret, | ||
audience: audience | ||
} | ||
post('/oauth/token', request_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each error type doesn't need accounted for by name, but it's up to you whether you'd like to catch errors here and return a single custom one or two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I think that's probably a good idea at some point, it's a breaking change to add that to all methods here and I don't want this to be any different than the others in that respect. I'll keep that in mind for the next major.
Really looking forward to this PR! |
ee6e9bd
to
f245673
Compare
f245673
to
5fc1f4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending passing build
…specific errors to expect
This PR adds a method to get an API access token with a Client Credentials grant is no token is passed directly to
Auth0::Client
during instantiation.Specific changes:
Auth0::Api::AuthenticationEndpoints::api_token
method that accepts anaudience
(defaults to the Management API audience for thedomain
used), performs a Client Credentials grant, and returns a hash of what was returned.Auth0::Client
instantiation to call this added method if no token was passedUsage:
To start using this new functionality, leave out
token
andaccess_token
and addclient_secret
when instantiatingAuth0::Client
:Auth0::Client.new
will see that you did not pass in a token and that there is aclient_secret
available and make a call tooauth/token
to retrieve an API token for your Application. This will require that:You can also use the method directly for other APIs:
Please note: the API token should only be fetched once and cached securely for re-use before the expiration time. Each call to
api_token
or instantiation ofAuth0::Client.new
will make an HTTP call to get a new token.Closes #86