コード例 #1
0
        public async Task <ApiUser> TryAuthenticate(IHttpContext context)
        {
            if (!Config.Instance.PasswordAuthentication.Enabled)
            {
                throw new NotFoundException();
            }

            var password = context.Request.QueryString["password"];

            if (string.IsNullOrEmpty(password))
            {
                throw new BadRequestException("Password query parameter is required.");
            }

            if (password != Config.Instance.PasswordAuthentication.Password)
            {
                throw new UnauthorizedException();
            }

            await context.SendResponse(HttpStatusCode.OK);

            return(PasswordApiUser.MakePasswordUser(context, password));
        }