twilio / voice-quickstart-ios

Twilio Voice Quickstart for iOS with Swift
MIT License
181 stars 95 forks source link

invalid access token header error #149

Closed aksh1995a closed 5 years ago

aksh1995a commented 6 years ago

I am getting invalid access token header error when I am trying to make an outbound call using the sdk and I have referenced QuickStart guide

this is my debugger log

2018-08-02 13:01:34.313694+0530 TwilioCall[701:166571] [DEBUG TVOConstants] X-Twilio-Client string: {"p":"ios","v":"2.0.4","mobile":{"arch":"arm64","product":"iPhone","name":"iPhone6,2","v":"11.4.1"}}, inside TVOConstants clientString 2018-08-02 13:01:34.329200+0530 TwilioCall[701:166571] [DEBUG TVOReachability] Reachability Flag Status: -R ------- networkStatusForFlags 2018-08-02 13:01:34.329519+0530 TwilioCall[701:166571] [DEBUG TVOCommandHandler] Inside postCommand:, received command of type TVOMakeCallCommand 2018-08-02 13:01:34.330168+0530 TwilioCall[701:166604] [VERBOSE Twilio] Inside constructUri: Registration URL: sip:None@chunderm.gll.twilio.com;transport=tls 2018-08-02 13:01:34.330269+0530 TwilioCall[701:166604] [INFO TVOMakeCallCommand] Call URI: sip:None@chunderm.gll.twilio.com;transport=tls 2018-08-02 13:01:34.338008+0530 TwilioCall[701:166604] [VERBOSE TVOCallImpl] Inside makeCall, record permission was granted 2018-08-02 13:01:34.340884+0530 TwilioCall[701:166604] [DEBUG Twilio] Inside on_call_state(), call: 0x107126840, internal state: 1 2018-08-02 13:01:34.341035+0530 TwilioCall[701:166604] [VERBOSE Twilio] Inside on_call_state(), PJSIP_INV_STATE_CALLING 2018-08-02 13:01:34.341264+0530 TwilioCall[701:166604] [VERBOSE TVOCall] handlePJSIPInviteStateCalling. Error: (null) 2018-08-02 13:01:34.341369+0530 TwilioCall[701:166604] [VERBOSE Twilio] on_call_tsx_state(), state: 1, status_code: 0: (null) 2018-08-02 13:01:35.911235+0530 TwilioCall[701:166645] [DEBUG Twilio] on_transport_state(): 0 2018-08-02 13:01:35.911774+0530 TwilioCall[701:166645] [DEBUG Twilio] ------>Transport connected: 0x3875428, inside transportConnected: 2018-08-02 13:01:36.215423+0530 TwilioCall[701:166645] [VERBOSE Twilio] Inside on_rx_response(): received INVITE response, rewriting contact 2018-08-02 13:01:36.217198+0530 TwilioCall[701:166645] [DEBUG Twilio] In on_call_redirected, call_id: 0, target: 0x10740cfe4, pjsip_event: 0x16f0f8658 2018-08-02 13:01:36.219271+0530 TwilioCall[701:166645] [VERBOSE Twilio] on_call_tsx_state(), state: 1, status_code: 0: (null) 2018-08-02 13:01:36.219752+0530 TwilioCall[701:166645] [VERBOSE Twilio] on_call_tsx_state(), state: 4, status_code: 302: Moved Temporarily 2018-08-02 13:01:36.221036+0530 TwilioCall[701:166645] [VERBOSE Twilio] on_call_tsx_state(), state: 6, status_code: 302: Moved Temporarily 2018-08-02 13:01:36.221579+0530 TwilioCall[701:166645] [DEBUG Twilio] ------>Destroying transport: 0x103875428, inside releaseTransport 2018-08-02 13:01:37.512422+0530 TwilioCall[701:166645] [DEBUG Twilio] on_transport_state(): 0 2018-08-02 13:01:37.512787+0530 TwilioCall[701:166645] [DEBUG Twilio] ------>Transport connected: 0x3885a28, inside transportConnected: 2018-08-02 13:01:37.769624+0530 TwilioCall[701:166645] [VERBOSE Twilio] Inside on_rx_response(): received INVITE response, rewriting contact 2018-08-02 13:01:37.771896+0530 TwilioCall[701:166645] [VERBOSE Twilio] on_call_tsx_state(), state: 4, status_code: 403: Forbidden 2018-08-02 13:01:37.772230+0530 TwilioCall[701:166645] [DEBUG Twilio] Inside on_call_state(), call: 0x107126840, internal state: 2 2018-08-02 13:01:37.772477+0530 TwilioCall[701:166645] [VERBOSE Twilio] Inside on_call_state(), PJSIP_INV_STATE_DISCONNECTED, internal state: 2, last_status: 403 2018-08-02 13:01:37.773319+0530 TwilioCall[701:166645] [VERBOSE TVOCall] handlePJSIPInviteStateDisconnected. Error: Error Domain=com.twilio.voice.error Code=20102 "Twilio Error 20102" UserInfo={NSLocalizedDescription=Twilio Error 20102, NSLocalizedFailureReason=Invalid Access Token header} 2018-08-02 13:01:37.777773+0530 TwilioCall[701:166571] Call failed to connect: Twilio Error 20102 2018-08-02 13:01:37.797099+0530 TwilioCall[701:166603] [DEBUG TwilioVoice] Inside removeFromActiveCalls:, remove call <TVOCall: 0x107126840> from active calls 2018-08-02 13:01:37.820064+0530 TwilioCall[701:166603] [DEBUG Twilio] dealloc Twilio. 2018-08-02 13:01:37.849124+0530 TwilioCall[701:166603] [DEBUG Twilio] ------>Destroying transport: 0x103885a28, inside releaseAllTransports 2018-08-02 13:01:37.870797+0530 TwilioCall[701:166603] [DEBUG Twilio] on_transport_state(): 2 2018-08-02 13:01:37.960169+0530 TwilioCall[701:166571] [INFO TVOCall] Inside publishConnectionEvent:, event type: error 2018-08-02 13:01:37.973564+0530 TwilioCall[701:166571] [VERBOSE TVOCall] Inside publisherConnectionEvent:, sending error event 2018-08-02 13:01:38.313894+0530 TwilioCall[701:166603] [DEBUG TVOCall] dealloc. 2018-08-02 13:01:39.416018+0530 TwilioCall[701:166722] [ERROR TVOEventPublisher] Failed to send request, status code: 403 2018-08-02 13:01:39.416232+0530 TwilioCall[701:166722] [VERBOSE TVOEventPublisher] - response body: {"code":20102,"message":"Invalid Access Token header"}

aksh1995a commented 6 years ago

and when twiliovoice.register func what is device token??

bobiechen-twilio commented 6 years ago

Hi @aksh1995a

What do you see when you feed your Access Token into https://jwt.io ? The error code and message indicated that the header of the token was not incorrect. It should look like:

{
  "alg": "HS256",
  "typ": "JWT",
  "cty": "twilio-fpa;v=1"
}

(Note: please don't post any of your personal account credentials, including the access token, in the public forum.)

Are you using any of the Twilio server helper library for token generation and if yes, which one are you using?

The deviceToken for the TwilioVoice.register() method is the device returned in the pkPushRegistry:didUpdatePushCredentials:forType: callback: https://github.com/twilio/voice-quickstart-swift/blob/master/SwiftVoiceCallKitQuickstart/ViewController.swift#L146

-bobie

aksh1995a commented 6 years ago

hello , I am using the same auth token for tcdevice and tcconnection it works fine!outgoing calls and all,but unfortunately I am not able to get callsid from those methods so I have to integrate through twiliovoice but here the same access token I used for device gives me error.       Inside register:deviceToken:completion:, failed to register for Twilio push notifications. Error:Invalid access token and the same for twiliovoice.call 

Error Domain=com.twilio.voice.error Code=20102 "Twilio Error 20102" UserInfo={NSLocalizedDescription=Twilio Error 20102, NSLocalizedFailureReason=Invalid Access Token header} I made changes in the header then error code was changed to 20103 but it also had same description. -Akshay

  From: bobiechen-twilio <notifications@github.com>

To: twilio/voice-quickstart-swift voice-quickstart-swift@noreply.github.com Cc: aksh1995a akshay@plash.in; Mention mention@noreply.github.com Sent: Thursday, 2 August 2018 11:18 PM Subject: Re: [twilio/voice-quickstart-swift] invalid access token header error (#149)

Hi @aksh1995aWhat do you see when you feed your Access Token into https://jwt.io ? The error code and message indicated that the header of the token was not incorrect. It should look like:{ "alg": "HS256", "typ": "JWT", "cty": "twilio-fpa;v=1" } (Note: please don't post any of your personal account credentials, including the access token, in the public forum.)Are you using any of the Twilio server helper library for token generation and if yes, which one are you using?The deviceToken for the TwilioVoice.register() method is the device returned in the pkPushRegistry:didUpdatePushCredentials:forType: callback: https://github.com/twilio/voice-quickstart-swift/blob/master/SwiftVoiceCallKitQuickstart/ViewController.swift#L146-bobie— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

bobiechen-twilio commented 6 years ago

Hi @aksh1995a

The Programmable Voice SDK requires a version of token that is different from the Capability Token used in the Twilio Client SDK. Please check out the Access Token page and update your token vending server endpoint.

Thanks -bobie

bobiechen-twilio commented 5 years ago

Hi @aksh1995a I am closing this ticket since there has been no activities for a while and assuming the original issue has been resolved. Please feel free to reach out to us if you run into any issue using the SDK.

Thanks -bobie

softsan commented 1 year ago

@bobiechen-twilio I am trying to integrate it in SwiftUI and i am getting an error while starting an outgoing call: Error Domain=com.twilo.voice.error Code=20102 "Invalid Access Token header" UserInfo={NSLocalizedDescription=Invalid Access Token header, NSLocalizedFailureReason=SIP/2.0 403 Forbidden}

I decoded the JWT Token and in header i see this: { "alg": "HS256", "typ": "JWT", "cty": "JWT" }

so what could be wrong in above token header? similar issue i posted here as well.

bobiechen-twilio commented 1 year ago

The cty (content type) should be twilio-fpa;v=1

softsan commented 1 year ago

@bobiechen-twilio Okay Thanks for the quick reply. Will check on my server side.

softsan commented 1 year ago

@bobiechen-twilio Confirming adjusting server logic fixed the problem. Thanks