2

我创建了一个新的 laravel 5.3 项目并根据本教程进行设置:https://mattstauffer.co/blog/introducing-laravel-passport

但是当我尝试通过从 Firefox 中的 http 请求插件发送安静的请求来检查 oauth 服务器时,我得到 Not Found - 404

我的请求网址:http://localhost/pcheck/user并且我已经设置了标题:"Application/json"

我的 web.php 路由文件:

// First route that user visits on consumer app Route::get('/redirect', function () { // Build the query parameter string to pass auth information to our request $query = http_build_query([ 'client_id' => 3, 'redirect_uri' => 'http://localhost/pcheck/callback', 'response_type' => 'code', 'scope' => 'conference' ]);

// Redirect the user to the OAuth authorization page
return redirect('http://localhost/pcheck/oauth/authorize?' . $query);

});

// Route that user is forwarded back to after approving on server Route::get('/callback', function (Request $request) { $http = new GuzzleHttp\Client;

$response = $http->post('http://localhost/pcheck/oauth/token', [
    'form_params' => [
        'grant_type' => 'authorization_code',
        'client_id' => '3',
        'client_secret' => 'azWM7CGS4UtIQ30sd5bwW5s53P52QjaRmUdWjKpx',
        'redirect_uri' => 'http://localhost/pcheck/callback',
        'code' => $request->code,
    ],
]);

return json_decode((string) $response->getBody(), true);

});

我的 api.php 路由文件:

Route::get('/user', function (Request $request) { return $request->user(); })->middleware('auth:api');

我不知道我错在哪里任何想法?

4

1 回答 1

0

我自己找到了解决方案。这是因为使用 sudo 命令安装 npm,我们必须在没有 sudo 的情况下安装 npm 模块。所以要解决这个问题,我们应该删除 npm 模块,然后运行 ​​npm install 并等待它安装所有需要的依赖项。

仅供参考:您的 bootstrap.js 文件和 package.json 文件应如下所示:

包.json:

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "bootstrap-sass": "^3.3.7",
    "buble": "^0.14.0",
    "buble-loader": "^0.2.1",
    "gulp": "^3.9.1",
    "jquery": "^3.1.0",
    "laravel-elixir": "^6.0.0-11",
    "laravel-elixir-vue-2": "^0.2.0",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.16.2",
    "vue": "^2.0.1",
    "vue-loader": "^9.7.0",
    "vue-resource": "^1.0.3",
    "webpack": "^2.1.0-beta.22"
  }
}

引导程序.js:

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

window.$ = window.jQuery = require('jquery');
require('bootstrap-sass');

/**
 * Vue is a modern JavaScript library for building interactive web interfaces
 * using reactive data binding and reusable components. Vue's API is clean
 * and simple, leaving you to focus on building your next great project.
 */

window.Vue = require('vue');
require('vue-resource');

/**
 * We'll register a HTTP interceptor to attach the "CSRF" header to each of
 * the outgoing requests issued by this application. The CSRF middleware
 * included with Laravel will automatically verify the header's value.
 */

Vue.http.interceptors.push((request, next) => {
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);

    next();
});


Vue.http.options.credentials = true; //very important
/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

// import Echo from "laravel-echo"

// window.Echo = new Echo({
//     broadcaster: 'pusher',
//     key: 'your-pusher-key'
// });

还有一个重要的提示,你应该使用最新的 npm 版本:6.9。

希望其他问题能用这个解决方案快速解决。

于 2016-10-23T05:05:15.623 回答