401 (Unauthorized) Error on Get method


#1

i have problem in moment get token using method get, when i test using postman response working. and when i try in ionic using this code i got response 401

  gettoken() {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Authorization', localStorage.getItem('id_token'));
          this.http.get(apiUrl+'token/auth',{}, {headers: headers})
          .subscribe(res => {
            console.log('ok');
          }, (err) => {
            reject(err);
          });
    });
  }

#2

Are you sure the request your Ionic app is sending looks identical to the one you create in Postman?

Take a look at the network panel in your browser’s dev tools.


#3

What is the value of apiUrl?


#4

i found the problem, so code ionic not send header value token, i try using this code. i check browser status response and result

but i login using my apps ionic and after login server receive key token

Screenshot_2

i think must if i’m logged with apps ionic this token is valid in apps ionic

  gettoken() {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Authorization', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSIsInVzZXJfbGV2ZWwiOiJ3b3JrZXIiLCJpYXQiOjE1MTMzMTM4ODEsImV4cCI6MTUxMzMxNzQ4M30.IYZ4BnjTZ3K9agI-UEkjVvyr1WvgorM97huMr1A6600');
          this.http.get(apiUrl+'token/auth',{}, {headers: headers})
          .subscribe(res => {
            resolve(res.json());
            console.log('ok');
          }, (err) => {
            reject(err);
          });
    });
  }

#5

in the form of the appropriate login owner data when the token is created


#6

What does the request this is sending out look like, its headers? You only shows the response which shows that the server doesn’t like what he is getting, but not what you are sending. Please do so.