Laravel护照未经应用程序而非邮递员身份验证

时间:2018-09-09 20:55:31

标签: laravel react-native laravel-passport

我的laravel护照有些麻烦。

我正在尝试从我的api中获取一些数据。从React本机应用程序从邮递员尝试时,它工作正常,但是当我从我的应用程序中进行操作时,它不起作用。怎么来的?

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');
});

当使用提取API从react-native应用程序提取数据时,响应为“未经身份验证”

0 个答案:

没有答案