Home > Back-end >  Twilio API in angular8 Not Authorized " 401 Unauthorized" but working fine on Postman
Twilio API in angular8 Not Authorized " 401 Unauthorized" but working fine on Postman

Time:03-11

I am trying to call Twilio API from Angular8 Application but i am getting below mentioned Error enter image description here

Error Text is message: "Http failure response for https://video.twilio.com/v1/Rooms: 401 Unauthorized" detail: "Your AccountSid or AuthToken was incorrect." Code that i am using in angular is

    const headers = new HttpHeaders({
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic QUM2NjNiMmY4ZTM3NWY1NjUwMjg4ZDE4NzMYzA==',
      "UniqueName": Name
    });
    return this.httpclient.post('https://video.twilio.com/v1/Rooms', { headers: headers });
  }

I have also try to change the Content-Type as application/json but still no success

Same Code i am using in postman and it is working fine

enter image description here

My ultimate goal is to create room and join as participant through video

CodePudding user response:

I highly recommend that you do not make this API call from your front-end application. To do so, you need to embed your credentials in the front-end and a malicious user would be able to extract them and abuse your account.

In your case, you have tried to include the base 64 encoded parameters as the Authorization header and I was able to extract your Account SID (though not your auth token, which is good for your security now!).

If you want to make requests to the Twilio API, I recommend you do that from your server side, that way you can keep your credentials secure.

  • Related