Method: OpenC3::TimelineWorker#get_token

Defined in:
lib/openc3/microservices/timeline_microservice.rb

#get_token(username) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/openc3/microservices/timeline_microservice.rb', line 44

def get_token(username)
  if ENV['OPENC3_API_CLIENT'].nil?
    ENV['OPENC3_API_PASSWORD'] ||= ENV['OPENC3_SERVICE_PASSWORD']
    return OpenC3Authentication.new().token
  else
    # Check for offline access token
    model = nil
    model = OpenC3::OfflineAccessModel.get_model(name: username, scope: @scope) if username and username != ''
    if model and model.offline_access_token
      auth = OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
      return auth.get_token_from_refresh_token(model.offline_access_token)
    else
      return nil
    end
  end
end