Example #1
0
        public async Task <IActionResult> RequestEngineToken(int engineId, RequestEngineTokenDto dto)
        {
            _logger.LogInformation("Requesting token for engine {engineId}. Request body: {@dto}", engineId, dto);

            var engine = await _catapultEngineService.GetCatapultEngine(engineId);

            if (!engine.IsActive)
            {
                _logger.LogWarning("Engine is suspended");
                return(BadRequest("Engine is suspended"));
            }

            var engineRole = await _catapultEngineService.GetCatapultEngineRole(engineId);

            var tokenKey      = _configuration["Security:Tokens:Key"];
            var tokenIssuer   = _configuration["Security:Tokens:Issuer"];
            var tokenAudience = _configuration["Security:Tokens:Audience"];

            var token = AuthorizationToken.GenerateEngineToken(engine.Name, engineRole, tokenKey, tokenIssuer, tokenAudience, dto?.Expires);

            return(Ok(token));
        }