Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

josnys's avatar

Laravel 5.3 API request from ionic return login page

Hi guys ! I'm developing a mobile app with ionic 2 and i also built my API using laravel 5.3 with passport for auth. If any of you have already worked with ionic, when i do "ionic serve" in the terminal and try at the same time to call an endpoint of my API like http://my.server/api/post to retrieve all posts passing the token i received after login, it returns HTML content to me like it was redirecting me to the login page of Laravel. Nonetheless i don't have this issue using postman. But keep in mind that when i hit the http://my.server/oauth/token everything works like a charm. What might be the cause of this ?

Here is a link of the screenshot i uploaded on google drive : https://drive.google.com/file/d/0BzCuAwfHiZJnWmU0Um4weG1FbVU/view?usp=sharing

0 likes
6 replies
geowrgetudor's avatar

Seems like your token is returned into the response but not stored. What Session driver are you using?

josnys's avatar

... BROADCAST_DRIVER=redis CACHE_DRIVER=redis SESSION_DRIVER=file QUEUE_DRIVER=sync ...

But one thing to note in the screenshot is that before sending the request to the endpoint i console.log the the token to make sure it's being sent in the header

josnys's avatar

@geowrge like i stated in the post, i use laravel passport for authentication

geowrgetudor's avatar

Pretty strange since it is working in Postman. Can you post a code sample of the request?

Also if you are using Apache 2.4 add this to the conf block. It might be related to the headers.

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
josnys's avatar

this.baseUrl = 'http://localhost:8000/api/';

return this.http.get(this.baseUrl+'events', { headers: this.headers()}) .map((res) => { console.log(res); res.json(); });

// headers function var credential = new Headers(); this.storage.get('lo_userAuth').then(value => { // console.log(value['token_type']+' '+value['access_token']); credential.append('Authorization', value['token_type']+' '+value['access_token']); credential.append('Accept', 'application/json '); credential.append('Content-Type', 'application/x-www-form-urlencoded'); }); console.log(credential); return credential;

Please or to participate in this conversation.