久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel Passport Route 重定向到登錄頁面

Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登錄頁面)
本文介紹了Laravel Passport Route 重定向到登錄頁面的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我使用的是 Laravel 5.3 &護(hù)照.

I'm using Laravel 5.3 & Passport.

當(dāng)使用 Postman 測試我在 api.php 文件中設(shè)置的任何路由時,它總是返回登錄頁面.這是我的測試路線示例:

When using Postman to test any route I have set in api.php file it always returns the login page. Here is an example of my testing route:

Route::get('/getKey', function() {
    return 'hello';
})->middleware('client_credentials');

郵遞員參數(shù):

Accept application/json
Authorization Bearer <then my key>

根據(jù)我在搜索答案時找到的另一個解決方案,我已將中間件設(shè)置為auth:api".

I have set middleware to 'auth:api' per another solution I found while searching for the answer.

protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('auth:api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

我已經(jīng)嘗試了幾乎所有對其他人有效的解決方案,但仍然沒有運(yùn)氣.任何建議將不勝感激.

I've tried just about every solution that has worked for others but still no luck. Any suggestions would be much appreciated.

更新所以我終于得到了一些工作.我創(chuàng)建了一個消費(fèi)者應(yīng)用程序并創(chuàng)建了一些測試功能.我能夠使用 api,并驗(yàn)證令牌.然而,點(diǎn)擊這條路線不再返回我的登錄頁面,而是現(xiàn)在什么都不返回.因此,無論出于何種原因,它仍然無法正常工作.

UPDATE So I finally got something to work. I created a consumer app and created a few test functions. I was able to consume the api, with verification of token. However, hitting this Route no longer returns my login page, but instead now returns nothing. So its still not working for whatever reason.

Route::get('/user', function (Request $request) {

    return $request->user();
})->middleware('client_credentials');

推薦答案

重定向到定義的登錄路由發(fā)生在 appExceptionsHandler.php 類中.

The redirection to the defined login route is occurring in the appExceptionsHandler.php class.

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }

    return redirect()->guest(route('login'));
}

該函數(shù)試圖檢測它是否被 API 調(diào)用(在這種情況下它返回一個帶有 JSON 消息的 401 Unauthorized 響應(yīng)),如果不是,它將根據(jù)它的評論重定向到登錄頁面

The function tries to detect whether it is being called from an API (it which case it returns a 401 Unauthorized reponse with JSON message) and if not it will redirect to the login page according to the comments it

將身份驗(yàn)證異常轉(zhuǎn)換為未經(jīng)身份驗(yàn)證的響應(yīng)

Converts an authentication exception into an unauthenticated response

要解決郵遞員中的問題,請在請求中單擊標(biāo)題"選項(xiàng)卡并添加:

To resolve the issue in postman, on the request click on the Headers tab and add:

key:   Accept
value: application/json

我對此很陌生,所以不確定這是我們應(yīng)該在使用 Postman 測試所有 API 調(diào)用時添加的標(biāo)頭,還是只是對如何設(shè)置此 laravel 方法感到不快.

I'm pretty new to this so am not sure whether this is a header we should be adding when testing all API calls with Postman or just a nusience with how this laravel method is setup.

無論如何,這將解決您被重定向到登錄頁面的問題,但這表明您的基礎(chǔ)身份驗(yàn)證不起作用

Anyway this would solve your issue with being redirected to the login page, however it's a sign your underlying authentication isn't working

這篇關(guān)于Laravel Passport Route 重定向到登錄頁面的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

add new element in laravel collection object(在 Laravel 集合對象中添加新元素)
Creating an edit modal in Laravel 5(在 Laravel 5 中創(chuàng)建編輯模式)
Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 資源(獨(dú)立數(shù)據(jù)))
What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中創(chuàng)建自定義輔助函數(shù)的最佳實(shí)踐是什么?)
No #39;Access-Control-Allow-Origin#39; header - Laravel(沒有“Access-Control-Allow-Origin標(biāo)頭 - Laravel)
How create package in Laravel 5?(如何在 Laravel 5 中創(chuàng)建包?)
主站蜘蛛池模板: 亚洲劲爆av| 欧美成人高清 | 成人免费观看男女羞羞视频 | 91精品国产综合久久久久久蜜臀 | 在线免费黄色 | 免费黄色在线观看 | 久久精品| 青青草av| 精品久久久久久18免费网站 | 日韩一级一区 | 九色91视频| 91n成人| 中文字幕亚洲视频 | 美国黄色毛片 | 中文字幕亚洲一区二区三区 | 日本精品视频 | 小h片免费观看久久久久 | 国产区视频在线观看 | h在线观看 | 成人免费视频在线观看 | 欧美在线一区视频 | 一区二区三区国产 | 成人av网站在线观看 | 亚洲国产精品99久久久久久久久 | 欧美精品一区二区在线观看 | 秋霞在线一区 | 日韩在线视频观看 | 国产va| 超碰在线人人 | 欧美自拍第一页 | 国产精品视频网址 | 国产日韩欧美在线观看 | 日韩福利片 | 在线观看黄视频 | 国产免费让你躁在线视频 | 精品久久中文字幕 | 在线免费观看黄网 | 999免费观看视频 | 精品三区 | 一区在线播放 | 99久久久久久 |