/// <summary> /// Authenticate application in the system and generate the access-key (token) /// </summary> /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete</param> private async Task <IActionResult> AuthenticateApplicationAsync(CancellationToken cancellationToken) { if (!AppKey.HasValue || !AppAccess.HasValue) { return(Unauthorized(_localizer["SCOPE_NOT_DEFINED"].Value)); } ScopeDto scope = await _scopeAppService.GetByKeyAsync(AppKey.Value, cancellationToken); if (scope == null || scope.AccessKey != AppAccess.Value) { return(Unauthorized(_localizer["INVALID_APP_KEY_ACCESS"].Value)); } if (!scope.AllowLogin || !scope.IsActive) { return(Unauthorized(_localizer["APP_LOGIN_DIALLOW"].Value)); } string token = _tokenHelper.GenerateTokenAplication(scope.Id, scope.Name, out DateTime? expiresIn); AuthenticateResponse result = new AuthenticateResponse(token, expiresIn, null, null); return(Ok(result)); }
///<inheritdoc/> protected override async Task <ScopeDto> GetByIdAsync(Guid key, CancellationToken cancellationToken = default) => await _scopeAppService.GetByKeyAsync(key, cancellationToken);