Exemple #1
0
        protected AuthByKeyResult HasAuthenticationKey(HttpRequest request)
        {
            if (!request.Headers.TryGetValue(KEY_HEADER, out StringValues values) || values.Count == 0)
            {
                return(new AuthByKeyResult
                {
                    Result = true
                });
            }

            string value = values[0];

            if (string.IsNullOrEmpty(value))
            {
                return(new AuthByKeyResult
                {
                    Result = true
                });
            }

            if (value.Length != 32)
            {
                return(new AuthByKeyResult
                {
                    ErrorResponse = new ErrorResponse("auth_header_is_incorrect")
                });
            }

            return(new AuthByKeyResult
            {
                Result = true,
                Key = AuthKey.Create(value)
            });
        }
Exemple #2
0
        protected AuthByKeyPairResult GetAuthenticationKeyPair(HttpRequest request)
        {
            if (!request.Headers.TryGetValue(KEY_HEADER, out StringValues values) || values.Count == 0)
            {
                return(new AuthByKeyPairResult
                {
                    Result = false,
                    ErrorResponse = new ErrorResponse("auth_header_not_set")
                });
            }

            string value = values[0];

            if (string.IsNullOrEmpty(value))
            {
                return(new AuthByKeyPairResult
                {
                    ErrorResponse = new ErrorResponse("auth_header_not_set")
                });
            }

            if (value.Length != 20)
            {
                return(new AuthByKeyPairResult
                {
                    ErrorResponse = new ErrorResponse("auth_header_is_incorrect")
                });
            }

            return(new AuthByKeyPairResult
            {
                Result = true,
                RegularKey = AuthKey.Create(value.Substring(10, 10)),
                SecuredKey = AuthKey.Create(value.Substring(0, 10))
            });
        }