vendredi 28 avril 2017

Laravel+Passport as oAuth server and axios+cordova as a client

Hello Coders,

My goal is to make an API on laravel so user get/post the data on other device /client. Client code is on axios+cordova. Am I on correct path or doing wrong. First time on Laravel + Passport API as well as on axios + cordova also.

Server Side

I setup server with the help of Laravel 5.6.4 + Passport and created token on Postman successfully.

oauth token

Client Side

Now I am trying to access user data through api/user default route in separate project, here is my code for that

AUTH_TOKEN                                     =    'Bearer eyJ0eXAiOiJKV1QiLCJ...';

axios.defaults.baseURL                         =    'http://sbs-api.dev';
axios.defaults.headers.common['Authorization'] =    AUTH_TOKEN;
axios.defaults.headers.post['Content-Type']    =    'application/x-www-form-urlencoded';

axios.get('/api/user')
    .then(function (response) {
        console.log(response);
})
.catch(function (error) {
    console.log(error);
});

but I'm unable to get user data instead of getting this error Network Error and/or Preflight Error. On Postman I am getting the data with same token.

enter image description here

Please tell me what is wrong with this code and/or provide some tutorials if possible.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire