无法使用 Directus v8 API 获取临时令牌 [英] Unable to get Temporary Token with Directus v8 API

查看:23
本文介绍了无法使用 Directus v8 API 获取临时令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的 Directus v8 版本.我安装了它并用它来设计我的架构,一切似乎都没问题,但是当我尝试获取临时令牌来对用户进行身份验证时,我收到一个关于未授权的奇怪错误,同时 AUTH 端点没有'不需要先前授权的用户(显然).

I am using the latest Directus v8 release. I installed it and used it to design my schema and everything seems to be ok, but when I try to get a temporary token to authenticate a user I am getting a strange error about not being authorized, at the same time that the AUTH endpoint doesn't require previously authorized users (obviously).

  • 我的 Directus 安装位于 htdocs/slotspanel
  • 它的网址是http://127.0.0.1/slotspanel
  • 仔细检查用户的凭据,它们是正确的
  • 我使用 XAMPP 和最新的 PHP7
  • mod_rewrite 已启用

我正在尝试使用以下脚本对用户进行身份验证

I am trying to authenticate the user with the following script

<?php

$data = array(
    'email'      => 'user@mail.com',
    'password'    => 'UserPasswordHere'
);

$options = array(
    'http' => array(
        'method'  => 'POST',
        'content' => json_encode( $data ),
        'header'=>  "Content-Type: application/json\r\n" .
                    "Accept: application/json\r\n"
    )
);

$context  = stream_context_create( $options );
$result = file_get_contents("http://127.0.0.1/slotspanel/auth/authenticate", false, $context);
$response = json_decode($result);

echo $response;

?>

我收到以下错误

Warning: file_get_contents(http://127.0.0.1/slotspanel/auth/authenticate): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in C:\xampp_new\htdocs\anotherdomain\index2.php on line 18

错误日志

[2020-06-18 13:36:29] api[auth].ERROR: Directus\Exception\UnauthorizedException: Unauthorized request in C:\xampp_new\htdocs\src\helpers\app.php:287
Stack trace:
#0 C:\xampp_new\htdocs\vendor\slim\slim\Slim\App.php(518): Directus\{closure}
#1 C:\xampp_new\htdocs\src\core\Directus\Application\Http\Middleware\CorsMiddleware.php(71): Slim\App->__invoke
#2 [internal function]: Directus\Application\Http\Middleware\CorsMiddleware->__invoke
#3 C:\xampp_new\htdocs\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array
#4 [internal function]: Slim\DeferredCallable->__invoke
#5 C:\xampp_new\htdocs\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func
#6 C:\xampp_new\htdocs\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}
#7 C:\xampp_new\htdocs\vendor\slim\slim\Slim\App.php(392): Slim\App->callMiddlewareStack
#8 C:\xampp_new\htdocs\vendor\slim\slim\Slim\App.php(297): Slim\App->process
#9 C:\xampp_new\htdocs\src\core\Directus\Application\Application.php(161): Slim\App->run
#10 C:\xampp_new\htdocs\slotspanel\index.php(5): Directus\Application\Application->run [] []

推荐答案

这是在 GitHub 上提出并随后解决的问题:https://github.com/directus/directus/discussions/2757#discussioncomment-27908

This was asked and subsequently resolved on GitHub: https://github.com/directus/directus/discussions/2757#discussioncomment-27908

http://127.0.0.1/slotspanel/auth/authenticate 上面的请求 URL 缺少路径中的项目.在这种特殊情况下,它应该是 http://127.0.0.1/slotspanel/slotspanel/auth/authenticate

The request URL above http://127.0.0.1/slotspanel/auth/authenticate was missing the project in the path. In this particular case, it was supposed to be http://127.0.0.1/slotspanel/slotspanel/auth/authenticate

这篇关于无法使用 Directus v8 API 获取临时令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆