久久久久久久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)建包?)
主站蜘蛛池模板: 超碰97免费观看 | 国产精品久久久久久久久久久久久 | 草草草影院 | 999精品视频在线观看 | 国产精品视频一二三区 | 亚洲视频网 | 日本三级线观看 视频 | 中文字幕av在线 | 亚洲国产精品一区二区第一页 | 亚洲高清在线观看 | 精品欧美一区二区在线观看欧美熟 | 一级毛片网| 国产91在线 | 亚洲 | 国内精品久久久久久 | 国产精品成人国产乱一区 | 亚洲成人精 | 精品无码久久久久久国产 | 人和拘一级毛片c | 国产成人一区二区三区久久久 | 日韩不卡一区二区三区 | 中文字幕高清 | 午夜激情小视频 | 国内av在线| 精国产品一区二区三区四季综 | 日韩在线欧美 | 国产精品一区二区在线 | 日一区二区 | 日韩国产专区 | 久久在线精品 | 欧美日日 | 日韩av在线免费 | 成人自拍视频网站 | 国产伦一区二区三区久久 | 日韩中文电影 | 91免费在线看 | 国产一区二区在线免费观看 | 精品一二区 | 99在线精品视频 | 久热久热 | 特级生活片 | 中文字幕精品视频 |