コード例 #1
0
        public ResultRequest <DtoTokenResponse> RefreshToken(
            [FromBody] InboundRequest <DtoRefreshToken> request)
        {
            try
            {
                var dto = request?.Data;
                if (dto == null)
                {
                    return(ResultRequest <DtoTokenResponse> .Error("Access Token request fail",
                                                                   "Invalid request data"));
                }

                var encryptedRefreshToken = dto.RefreshToken;
                if (string.IsNullOrEmpty(encryptedRefreshToken))
                {
                    throw new LogicException(
                              "Refresh Token is required for grantType RefreshToken");
                }

                var tokenFromRefreshToken = _service.GetNewTokenFromRefreshToken(encryptedRefreshToken);

                return(ResultRequest <DtoTokenResponse> .Ok(tokenFromRefreshToken));
            }
            catch (Exception e)
            {
                return(ResultRequest <DtoTokenResponse> .Error("Access Token request error",
                                                               e.Message));
            }
        }
コード例 #2
0
        public Task <ResultRequest> BlockUserToken([FromBody] InboundRequest <DtoUserToken> request)
        {
            try
            {
                var dto = request?.Data;
                if (dto == null || (string.IsNullOrEmpty(dto.UserId) && string.IsNullOrEmpty(dto.Token)))
                {
                    return(Task.FromResult(ResultRequest.Error("Access Token request fail", "Invalid request data")));
                }

                var allTokens = string.IsNullOrEmpty(dto.Token);
                if (allTokens)
                {
                    UserTokenMapping.Remove(dto.UserId, true);
                }
                else
                {
                    UserTokenMapping.Remove(dto.UserId, new UserToken
                    {
                        UserId = dto.UserId,
                        Token  = dto.Token
                    });
                }

                return(Task.FromResult(ResultRequest.Ok()));
            }
            catch (Exception e)
            {
                return(Task.FromResult(ResultRequest.Error("Access Token request error", e.Message)));
            }
        }
コード例 #3
0
        public async Task <ResultRequest <DtoTokenResponse> > LoginWithApiKey(
            [FromBody] InboundRequest <DtoAuthApiKey> request)
        {
            try
            {
                var dto = request?.Data;
                if (dto == null)
                {
                    return(ResultRequest <DtoTokenResponse> .Error("Access Token request fail",
                                                                   "Invalid request data"));
                }

                var token = await _service.GenerateToken(dto.ApiKey);

                return(ResultRequest <DtoTokenResponse> .Ok(token));
            }
            catch (Exception e)
            {
                return(ResultRequest <DtoTokenResponse> .Error("Access Token request error",
                                                               e.Message));
            }
        }