@@ -15,10 +15,27 @@ class AccessToken # rubocop:disable Metrics/ClassLength
1515 class << self
1616 # Initializes an AccessToken from a Hash
1717 #
18- # @param [Client] client the OAuth2::Client instance
19- # @param [Hash] hash a hash of AccessToken property values
20- # @option hash [String, Symbol] 'access_token', 'id_token', 'token', :access_token, :id_token, or :token the access token
21- # @return [AccessToken] the initialized AccessToken
18+ # @param [OAuth2::Client] client the OAuth2::Client instance
19+ # @param [Hash] hash a hash containing the token and other properties
20+ # @option hash [String] 'access_token' the access token value
21+ # @option hash [String] 'id_token' alternative key for the access token value
22+ # @option hash [String] 'token' alternative key for the access token value
23+ # @option hash [String] 'refresh_token' (optional) the refresh token value
24+ # @option hash [Integer, String] 'expires_in' (optional) number of seconds until token expires
25+ # @option hash [Integer, String] 'expires_at' (optional) epoch time in seconds when token expires
26+ # @option hash [Integer, String] 'expires_latency' (optional) seconds to reduce token validity by
27+ #
28+ # @return [OAuth2::AccessToken] the initialized AccessToken
29+ #
30+ # @note The method will use the first found token key in the following order:
31+ # 'access_token', 'id_token', 'token' (or their symbolic versions)
32+ # @note If multiple token keys are present, a warning will be issued unless
33+ # OAuth2.config.silence_extra_tokens_warning is true
34+ # @note For "soon-to-expire"/"clock-skew" functionality see the `:expires_latency` option.
35+ #
36+ # @example
37+ # hash = { 'access_token' => 'token_value', 'refresh_token' => 'refresh_value' }
38+ # access_token = OAuth2::AccessToken.from_hash(client, hash)
2239 def from_hash ( client , hash )
2340 fresh = hash . dup
2441 supported_keys = TOKEN_KEY_LOOKUP & fresh . keys
@@ -50,6 +67,16 @@ def extra_tokens_warning(supported_keys, key)
5067
5168 # Initialize an AccessToken
5269 #
70+ # @note For "soon-to-expire"/"clock-skew" functionality see the `:expires_latency` option.
71+ # @note If no token is provided, the AccessToken will be considered invalid.
72+ # This is to prevent the possibility of a token being accidentally
73+ # created with no token value.
74+ # If you want to create an AccessToken with no token value,
75+ # you can pass in an empty string or nil for the token value.
76+ # If you want to create an AccessToken with no token value and
77+ # no refresh token, you can pass in an empty string or nil for the
78+ # token value and nil for the refresh token, and `raise_errors: false`.
79+ #
5380 # @param [Client] client the OAuth2::Client instance
5481 # @param [String] token the Access Token value (optional, may not be used in refresh flows)
5582 # @param [Hash] opts the options to create the Access Token with
0 commit comments