twilio / voice-quickstart-objc

Twilio Voice Quickstart for iOS with Objective-C
MIT License
39 stars 24 forks source link

Invalid Access Token with header error Code=20101 status - 503 #169

Closed navaranjithavelladurai closed 5 years ago

navaranjithavelladurai commented 5 years ago

Im facing this below issue, i used twilio for the purpose of voice call & i updated my pod file to 'TwilioVoice', '~> 3.0'

Here i'am using the below function to make a call



        guard let accessToken = fetchAccessToken() else {
            completionHandler(false)
            return
        }

        let connectOptions: TVOConnectOptions = TVOConnectOptions(accessToken: accessToken) { (builder) in
            builder.params = [twimlParamTo : "xxxxxPhonenumber"]
            builder.uuid = uuid
        }
        call = TwilioVoice.connect(with: connectOptions, delegate: self)
    }```

But i get the below error: 
 Via: SIP/2.0/TLS 192.168.43.72;received=157.50.82.138;branch=z9hG4bK-524287-1---136cd36cff6d6463;rport=64801

Contact: <sip:172.19.69.244:10193>

To: <sip:chunderm.gll.twilio.com:443;transport=tls>;tag=28558475_6772d868_1a72b137-32f1-4158-b55d-2cc1243f9c9c

From: <sip:VoiceSDK@chunderm.gll.twilio.com>;tag=ec0c9a71

Call-ID: 7-k7zY9e7MEWUehSGM4Y5A..

CSeq: 1 INVITE

Server: Twilio

X-Twilio-Error: 20101 Invalid Access Token

X-Twilio-EdgeHost: ec2-54-169-64-131.ap-southeast-1.compute.amazonaws.com

X-Twilio-EdgeRegion: sg1

X-Twilio-Zone: ASIAPAC_SINGAPORE

Content-Length: 0

}
2019-04-29 22:37:50.661968+0530 TwilioSample[2250:343053] ERROR:Twilio:[Platform]:Failed to send request, status code: 503
navaranjithavelladurai commented 5 years ago

Kindly give some suggestion its urgent, let you know me what i did wrong

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

It's hard to tell what exact is causing the error with seeing the access token but basically the operation failed because the Access Token is invalid (either the format is wrong or the credentials are incorrect) and caused the authentication to fail.

Please check your Access Token in https://jwt.io/ and make sure you have all the credentials in it. You should see something like this:

{
  "iss": "SKdeadbeedeadbeedeadbeedeadbeedead",
  "grants": {
    "voice": {
      "outgoing": {
        "application_sid": "APdeadbeedeadbeedeadbeedeadbeedead"
      },
      "push_credential_sid": "CRdeadbeedeadbeedeadbeedeadbeedead"
    },
    "identity": "alice"
  },
  "sub": "ACdeadbeedeadbeedeadbeedeadbeedead",
  "exp": 1556641693,
  "nbf": 1556555293
}

-bobie

navaranjithavelladurai commented 5 years ago

No same crediential is working fine in android studio, but iOS only facing the issues

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

The 20101 Invalid Access Token error indicates that either the format of the Access Token is invalid or the credentials or the identity in the token are invalid. Could you please check the contents of the Access Token?

Thanks, -bobie

navaranjithavelladurai commented 5 years ago

Here i formed & get the access token

let baseURLString = "https://xxxxxxx" //let accessTokenEndpoint = "/accessToken" let identity = "alice" let twimlParamTo = "to"

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

Thanks for providing the code snippet. Please check the credentials in the Access Token generated from this URL are correct. I have a feeling that the Access Token string you received in the iOS application is in incorrect format since the Access Token should not have platform (Android/iOS) dependencies except for the Push Credential SIDs.

-bobie

navaranjithavelladurai commented 5 years ago

could you please provide the dummy Access Token for test case purpose?

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

A random string like ACCESS_TOKEN should give you the error. Please make sure the Access Token is valid when calling the SDK methods.

-bobie

navaranjithavelladurai commented 5 years ago

yah offcourse i tried to put the access token in https://jwt.io/ means, & its shows valid access token.

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

Please paste the contents (but mask your credentials) of the payload parsed from your Access Token.

-bobie

navaranjithavelladurai commented 5 years ago

Kindly check the below contents Header { "typ": "JWT", "alg": "HS384", "cty": "twilio-fpa;v=1" }

Payload { "jti": "xxxxxx", "iss": "xxxxx", "sub": "xxxx", "exp": 1556789315, "grants": { "voice": { "outgoing": { "application_sid": "xxxxxx" } } } }

Verified signature HMACSHA384( base64UrlEncode(header) + "." + base64UrlEncode(payload),

your-256-bit-secret

) secret base64 encoded

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

Assuming the masked credentials are correct (including the secret of the API Key), you would probably want to check if the identity is properly specified in the Access Token.

navaranjithavelladurai commented 5 years ago

I passed my identity as: let baseURLString = "https://xxxxx" //let accessTokenEndpoint = "/accessToken" let identity = "alice" let twimlParamTo = "to"

Here i formed the baseUrl : guard let accessTokenURL = URL(string: baseURLString) else { return nil } return try? String.init(contentsOf: accessTokenURL, encoding: .utf8)

Here i get the response: let connectOptions: TVOConnectOptions = TVOConnectOptions(accessToken: accessToken) { (builder) in builder.params = [twimlParamTo : "+91xxxxxxxx"] //builder.uuid = uuid print(accessToken) } call = TwilioVoice.connect(with: connectOptions, delegate: self)

Kindly give the suggestion, if i need to do change anything in the above code

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

Thanks for providing the snippet. Not sure if I am missing something but can you explain how where is the accessToken variable being updated and assigned? and what contents are you seeing after the token is parsed by https://jwt.io ? If you think the contents of the token does match the format in my previous comment and the credentials are all correct, please go to Twilio Support and create a support ticket. There you can provide us the Access Token safely and we can help you debug. Please also tag the link of this issue in the support ticket so the support representative person knows which team they need to reach out to.

Thanks, -bobie

navaranjithavelladurai commented 5 years ago

Okay thank you for support & time & i created a tickets in Twilio support as per your above comment, Kindly check it please.

bobiechen-twilio commented 5 years ago

Hi @navaranjithavelladurai

I am assuming that the authentication problem has been resolved and things are working on your end. Closing the ticket for now but feel free to reach out to us if you run into any issue in the future.

Thanks, -bobie