Sha256: 7118535407a3ee9a098a41c05e6200d35c4ff114e72c7113b4acd99ae16db228
Contents?: true
Size: 945 Bytes
Versions: 6
Compression:
Stored size: 945 Bytes
Contents
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 def get_token has_expired = @token && @token_expires_at ? @token_expires_at < (Time.now.to_i + 10) : false if (@token.nil? || has_expired) && @client_id && @client_secret response = api_token(audience: @audience) @token = response.token @token_expires_at = response.expires_in ? Time.now.to_i + response.expires_in : nil @token else @token end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems