-
Notifications
You must be signed in to change notification settings - Fork 141
Make Auth0::Client#get_token public #725
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,14 @@ | ||
| module Auth0 | ||
| module Mixins | ||
| module TokenManagement | ||
|
|
||
| private | ||
|
|
||
| def initialize_token(options) | ||
| @token = options[:access_token] || options[:token] | ||
| # default expiry to an hour if a token was given but no expires_at | ||
| @token_expires_at = @token ? options[:token_expires_at] || Time.now.to_i + 3600 : nil | ||
|
|
||
| @audience = options[:api_identifier] || "https://#{@domain}/api/v2/" | ||
| get_token() if @token.nil? | ||
| end | ||
|
|
||
| # Get the Client's api token (or generate a new one if it has expired). | ||
| # | ||
| # @note This method may perform a network request to refresh an expired token. It is not thread-safe. | ||
| # @return [String] the api token | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 LOW · conventions The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one could mislead. It tells callers to nil-guard against a scenario that means the client is broken. A misconfigured client should fail loudly at init, not silently return nil. Documenting nil as valid makes a bug look like expected behavior. |
||
| def get_token | ||
|
arpit-jn marked this conversation as resolved.
|
||
| # pp @token_expires_at | ||
| has_expired = @token && @token_expires_at ? @token_expires_at < (Time.now.to_i + 10) : false | ||
|
|
||
| if (@token.nil? || has_expired) && @client_id && (@client_secret || @client_assertion_signing_key) | ||
| response = api_token(audience: @audience) | ||
| @token = response.token | ||
|
|
@@ -27,6 +19,17 @@ def get_token | |
| @token | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def initialize_token(options) | ||
| @token = options[:access_token] || options[:token] | ||
| # default expiry to an hour if a token was given but no expires_at | ||
| @token_expires_at = @token ? options[:token_expires_at] || Time.now.to_i + 3600 : nil | ||
|
|
||
| @audience = options[:api_identifier] || "https://#{@domain}/api/v2/" | ||
| get_token() if @token.nil? | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.