lib/jamf/api/connection/token.rb
# Use this token to get a fresh one. If a pw is provided
# try to use it to get a new token if a proper refresh fails.
#
# @param pw [String] Optional password to use if token refresh fails.
#   Must be the correct passwd or the token's user (obviously)
#
# @return [Jamf::Timestamp] the new expiration time
#
Use this token to get a fresh one. If a pw is provided
try to use it to get a new token if a proper refresh fails.
Use this token to get a fresh one . If a pw is provided try to use it to get a new token if a proper refresh fails .
def refresh(pw = nil)
        if expired?
          return refresh_with_passwd(pw, :expired_refreshed, :expired_pw_failed) if pw
          @last_refresh_result = :expired_no_pw
          raise Jamf::InvalidTokenError, 'Token has expired'
        end
        keep_alive_token_resp = token_connection(KEEP_ALIVE_RSRC, token: @auth_token).post
        if keep_alive_token_resp.success?
          parse_token_from_response keep_alive_token_resp
          @last_refresh_result = :refreshed
          return expires
        end
        return refresh_with_passwd(pw, :refreshed_with_pw, :refresh_failed_no_pw) if pw
        @last_refresh_result = :refresh_failed
        raise 'An error occurred while refreshing the token' unless pw
      end
def refresh ( pw = nil ) if expired? return refresh_with_passwd ( pw , :expired_refreshed , :expired_pw_failed ) if pw @last_refresh_result = :expired_no_pw raise Jamf :: InvalidTokenError , 'Token has expired' end keep_alive_token_resp = token_connection ( KEEP_ALIVE_RSRC , token : @auth_token ) . post if keep_alive_token_resp . success? parse_token_from_response keep_alive_token_resp @last_refresh_result = :refreshed return expires end return refresh_with_passwd ( pw , :refreshed_with_pw , :refresh_failed_no_pw ) if pw @last_refresh_result = :refresh_failed raise 'An error occurred while refreshing the token' unless pw end
Use this token to get a fresh one.
Use this token to get a fresh one .
# gotta have a pw if expired # try the passwd # no passwd? no chance! # Now try a normal refresh of our non-expired token # if we're here, the normal refresh failed, so try the pw # if we're here, no pw? no chance!
the new expiration time
the new expiration time
Jamf::Timestamp
pw
Optional password to use if token refresh fails. Must be the correct passwd or the token's user (obviously)
Optional password to use if token refresh fails . Must be the correct passwd or the token ' s user ( obviously )