I trying to embed Twilio's Programmable video into my Android app.
I've created an endpoint on my java server, which uses "com.twilio.sdk" % "twilio-java-sdk" % "6.3.0" library for obtaining access tokens with following code:
private static final String ACCOUNT_SID = "ACxxxxx";
private static final String API_KEY_SID = "SKxxxxx";
private static final String API_KEY_SECRET = "aa8xxxxx";
private static final String TWILIO_CONFIGURATION_SID = "VSxxxxx";
public Result token(String identity) {
return ok(Json.toJson(new ResponseMessage(createToken(identity))));
}
public static String createToken(String identity) {
ConversationsGrant grant = new ConversationsGrant();
grant.configurationProfileSid = TWILIO_CONFIGURATION_SID;
AccessToken token = new AccessToken.Builder(
ACCOUNT_SID,
API_KEY_SID,
API_KEY_SECRET
).identity(identity).grant(grant).ttl(86400).build();
return token.toJWT();
}
Then I receiving a token in my Android app from this endpoint, and instantiating AccessManager with this token
new AccessManager(MyActivity.this,
videoToken,
new AccessManager.Listener() {
@Override
public void onTokenExpired(AccessManager twilioAccessManager) {
//Expired :(
}
@Override
public void onTokenUpdated(AccessManager twilioAccessManager) {
//Updated!
});
, and trying to create TwilioConversationsClient with following code in the accessManagerListener:
TwilioConversationsClient.create(twilioAccessManager, new TwilioConversationsClient.Listener() {
@Override
public void onStartListeningForInvites(TwilioConversationsClient conversationsClient) {
Log.d(TAG, "TwilioConversationsClient.Listener: onStartListeningForInvites");
}
@Override
public void onStopListeningForInvites(TwilioConversationsClient conversationsClient) {
Log.d(TAG, "TwilioConversationsClient.Listener: onStopListeningForInvites");
}
@Override
public void onFailedToStartListening(TwilioConversationsClient conversationsClientd,
TwilioConversationsException e) {
Log.d(TAG, "TwilioConversationsClient.Listener: onFailedToStartListening");
});
Evetytime I getting into 'onFailedToStartListening' callback with error message:
com.twilio.conversations.TwilioConversationsException: code:103, message: 31201 Authentication failed
The strangest thing, is if I copy new token from '//Updated!' block (see above), and paste it into code manually in
new AccessManager(MyActivity.this,
videoToken
instead videoToken, that I receiving from server just a seconds before, everything works smooth, and I getting into onStartListeningForInvites callback. Maybe something wrong with server encoding or encoding when I trying to read an answer? I spend a few days, but still can't resolve this problem.
And even more, I tried to replace my java server code with PHP, and got the same result! If I generating a token in the console (terminal), and then pasting it into Android app code, everything works good. But if I trying to get a token from remote server, I getting the same error with 'code:103, message: 31201 Authentication failed'.
I also using integrations with Twilio Voice, and Ip-Messaging, and I've never had problems with tokens.
If we will decode JWT tokens (one from server, and another generated locally), we will see than only difference is time of creation and expiration time:
Any suggestions appreciated!