示例#1
0
        /// <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));
        }
示例#2
0
        /// <summary>
        /// Request credentials for first access
        /// </summary>
        /// <param name="email">User e-mail</param>
        /// <param name="urlCredential">Url of the page to be informed in the credential creation email. The parameters 'type=create' and 'token={token}' will be added via query-string</param>
        /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete</param>
        protected async Task <IActionResult> GetFirstAccessAsync(string email, string urlCredential, CancellationToken cancellationToken = default)
        {
            PasswordProcessResult result = await _appService.GetFirstAccessAsync(email, _tokenHelper.GenerateTokenAplication(AppKey.Value, "RSoft.Auth", out _), urlCredential, cancellationToken);

            if (result.Success)
            {
                return(Ok(_localizer["TOKEN_FIRST_ACCESS_MAIL"].Value));
            }

            if (result.IsException)
            {
                return(HandleException(500, result.Exception));
            }

            return(BadRequest(PrepareNotifications(result.Errors)));
        }