Class: Legion::Extensions::MicrosoftTeams::Actor::TokenRefresher

Inherits:
Actors::Every
  • Object
show all
Defined in:
lib/legion/extensions/microsoft_teams/actors/token_refresher.rb

Constant Summary collapse

DEFAULT_REFRESH_INTERVAL =
900

Instance Method Summary collapse

Instance Method Details

#check_subtask?Boolean

Returns:

  • (Boolean)


14
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 14

def check_subtask?  = false

#enabled?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 25

def enabled?
  defined?(Legion::Extensions::MicrosoftTeams::Helpers::TokenCache)
rescue StandardError => e
  log.debug("TokenRefresher#enabled?: #{e.message}")
  false
end

#generate_task?Boolean

Returns:

  • (Boolean)


15
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 15

def generate_task?  = false

#manualObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 36

def manual
  log.debug('TokenRefresher tick')
  unless token_cache.authenticated?
    log.debug('No active delegated token, skipping refresh')
    return
  end

  log.info('Checking delegated token freshness')
  token = token_cache.cached_delegated_token
  if token
    log.info('Delegated token still valid, persisting')
    token_cache.save_to_vault
  elsif token_cache.previously_authenticated?
    log.warn('Delegated token expired, attempting browser re-auth')
    attempt_browser_reauth(token_cache)
  else
    log.warn('Delegated token expired, no previous auth to restore')
  end
rescue StandardError => e
  log.error("TokenRefresher: #{e.message}")
end

#run_now?Boolean

Returns:

  • (Boolean)


12
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 12

def run_now?        = false

#runner_classObject



10
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 10

def runner_class    = Legion::Extensions::MicrosoftTeams::Helpers::TokenCache

#runner_functionObject



11
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 11

def runner_function = 'cached_delegated_token'

#timeObject



17
18
19
20
21
22
23
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 17

def time
  settings = teams_auth_settings
  delegated = settings[:delegated]
  return DEFAULT_REFRESH_INTERVAL unless delegated.is_a?(Hash)

  delegated[:refresh_interval] || DEFAULT_REFRESH_INTERVAL
end

#token_cacheObject



32
33
34
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 32

def token_cache
  Legion::Extensions::MicrosoftTeams::Helpers::TokenCache.instance
end

#use_runner?Boolean

Returns:

  • (Boolean)


13
# File 'lib/legion/extensions/microsoft_teams/actors/token_refresher.rb', line 13

def use_runner?     = false