Initial commit

This commit is contained in:
Senad Uka
2022-03-23 05:44:42 +01:00
parent 1405281a5c
commit eea10dd03b
113 changed files with 3617 additions and 81 deletions

View File

@@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'auth/token_service'
# Manages tokens for this App
module Auth
class AuthTokenService
include Singleton
def refresh
@tokens = mutex.synchronize { obtain_tokens }
end
def access_token
ensure_tokens
@tokens[:access_token]
end
private
def ensure_tokens
@tokens ||= mutex.synchronize { obtain_tokens }
end
def obtain_tokens
token_source.fetch('client_credentials', client_id, client_secret)
end
def mutex
@mutex ||= Mutex.new
end
def token_source
@token_source ||= Auth::TokenService.new(auth_url)
end
def client_id
AppConfig.auth.client_id
end
def client_secret
AppConfig.auth.client_secret
end
def auth_url
URI(AppConfig.auth.url)
end
end
end