title: Twilio Chat - Javascript SDK - Error: The authorization with Token failed
body: <p>I am using a PHP server to generate token. When I initialize the chat client with the token generated, I am getting this error.</p>
  
  <blockquote>
    <p>POST <a href="https://ems.us1.twilio.com/v1/token" rel="nofollow noreferrer">https://ems.us1.twilio.com/v1/token</a> 401 (Unauthorized)</p>
    
    <p>{"message":"The authorization with Token
    failed","code":2016,"user_error":false,"params":{"description":"Could
    not authenticate fpa token"}} </p>
    
    <p>EMS E: Error: The authorization with Token failed</p>
  </blockquote>
  
  <p>Javascript (v2.1) initilization code:</p>
  
  <pre><code>    Twilio.Chat.Client.create(token).then(client =&gt; {
          chatClient = client;
          chatClient.getChannelByUniqueName(channelName)
          .then(function(chosenChannel) {
              myChannel=chosenChannel;
  </code></pre>
  
  <p>PHP Server code:</p>
  
  <pre><code>    $token = new AccessToken( $accountid, $apikey, $apisecret 3600, 
      $identity);
  
  
      $chatGrant = new ChatGrant();
      $chatGrant-&gt;setServiceSid($configs[1]);
      $chatGrant-&gt;setEndpointId($endpointId);
  
      $token-&gt;addGrant($chatGrant);
  
      return $token-&gt;toJWT(); 
  </code></pre>
  
  <p>Any help?</p>