【问题标题】:Laravel passport unauthenticated from app not from postmanLaravel 护照未经来自应用程序而非邮递员的身份验证
【发布时间】:2018-09-10 16:13:43
【问题描述】:

我在使用 laravel 护照时遇到了一些问题。

我正在尝试从我的 api 中获取一些数据。来自反应原生应用程序。从邮递员那里尝试它时效果很好,但是当我从我的应用程序中尝试它时它不起作用。怎么来的?

AsyncStorage.getItem('TOKEN').then(token => {
    fetch(BACKEND_URL + '/api/getdata/', {
        method: 'GET',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + token,
        },
    })
    .then(response => response.json())
    .then(responseJson => {
        console.log(responseJson);
        this.setState({
            data: responseJson.data,
            isLoading: false,
        });

    }) 
    .catch(error => {
        console.error(error);
    });
});
//DataController.php
public function fetchdataAPI()
{
    $user = auth('api')->user();

    $data = Data::all();

    return response()->json([
        'data' => $data,
    ]);
}
//API.php
Route::group(['middleware' => 'auth:api'], function(){

Route::get('getdata','dataController@fetchDataAPI');
});

当使用 fetch api 从 react-native 应用程序获取数据时,响应是“未经身份验证”

【问题讨论】:

  • 这在使用代客共享和使用 https 链接时可以在本地正常工作。这可能是 SSL 问题吗?
  • 嗨,J.Wennergren,我面临同样的问题。你解决了吗?
  • 解决方案是将令牌添加到 url。像这样:BACKEND_URL + '/api/getdata/' + '?token=' + token
  • 我也遇到了同样的问题。 @Imran 你像他说的那样解决了吗?

标签: laravel react-native laravel-passport


【解决方案1】:

确保后端 URL 相同,包括协议(SSL 问题)。

【讨论】:

    猜你喜欢
    • 2017-01-06
    • 2019-02-28
    • 2019-06-14
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 2018-05-02
    相关资源
    最近更新 更多