【发布时间】:2022-10-14 04:05:21
【问题描述】:
在使用我的 api 时,如何创建一个 Laravel Gate,其中客户端必须在标头中提供 CSRF 令牌?
想法是在使用我的路线时我想要某种门: http://127.0.0.1:50004/api/third-party/unsplash
否则,任何人都可以复制和使用上述路线。
api.php
Route::get('/third-party/unsplash', [UnsplashController::class, 'show'])
**// my gate here!!!!**
UnsplashController.php
public function show()
{
return ['authorizationKey' => 'Client-ID 1234'];
}
Unsplash.vue 文件:
const myAsync = async function fetchUnsplash() {
const myAPIKey = await fetch(
'http://127.0.0.1:50004/api/third-party/unsplash'
);
const dataMyAPIKey = await myAPIKey.json();
const response = await fetch('https://api.unsplash.com', {
headers: {
Authorization: dataMyAPIKey,
},
});
console.log(response);
};
【问题讨论】:
-
你想保护你的 api 路由吗?
-
是的。我想保护我的 api 路由。