Twilio configuration Profile SID - twilio

I am using the Twilio Video API. In my node.js I used this code,
var grant = new VideoGrant();
It requires configurationProfileSid but I can't find docs on how to get it?
I think it is a capability token.
But how can I get it using twilio node js?
Or is there any other way to get it?

Twilio developer evangelist here.
Configuration Profiles used to be required, but have been deprecated. So you no longer need the configurationProfileSid. You can give access to particular rooms though.
Here's an example Node.js application that generates access tokens for a Video application. The important part is the route that generates the token:
app.get('/', function(request, response) {
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
// Assign identity to the token
token.identity = request.query.identity || 'identity';
// Grant the access token Twilio Video capabilities
var grant = new VideoGrant();
grant.room = request.query.room;
token.addGrant(grant);
// Serialize the token to a JWT string
response.send(token.toJwt());
});
This documentation on access tokens should help too.

Related

Retrieving Message Service Name from Twilio's Phone Numbers API

I'm using the IncomingPhoneNumber resource (https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) to retrieve infomration about my phone numbers in Twilio.
Both .ReadAsync and .FetchAsync return numbers that I've bought via the Twilio console, and some of those numbers are in a Sender Pool for messaging services.
However, the payload returned by either of those two methods does not contain whether or not a phone number is in a message service pool.
On the console, you can see if a phone number belongs to a message service.
Is it possible, using the IncomingPhoneNumber Resource REST API to find out if a phone number is part of a messaging service?
No, the IncomingPhoneNumber resource won't be able to tell you that. But the PhoneNumber Resource of the Messaging Service API will be able to tell you (or help modify the assignments).
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messaging.v1.services('MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.phoneNumbers
.list({limit: 20})
.then(phoneNumbers => phoneNumbers.forEach(p => console.log(p.sid)));

Twilio multiple push credential sid

I'm trying to implement Twilio swift quick start app, anyway I want to configure the app on both platforms iOS and Android,
I reached step 8 in the iOS tutorial
and I have a new PUSH_CREDENTIAL_SID for the iOS from the APN type, while the Android app is from the FCM type already have a PUSH_CREDENTIAL_SID that is being used in the config server file.
$ACCOUNT_SID = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$API_KEY_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$PUSH_CREDENTIAL_SID = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$APP_SID = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
How can I Add multiple PUSH_CREDENTIAL_SIDs for both apps ? or is there another way to figure this out ?
Thanks in advance
In your code you can have only 1 push_credential_sid.
In order to use the android AND ios at the same time, you should go into your project using this link: https://www.twilio.com/console/notify/services
Create a new service, and you will be able to create a service with the serviceID for android and IOS.
It will provide you a new serviceID to (SID) to use in your backend code.
And it should work for both platform :)
source : https://www.twilio.com/docs/notify/configure-ios-push-notifications#configure-your-twilio-service-to-use-your-apns-credentials
From the backend server, it only can config one push service id in 'PUSH_CREDENTIAL_SID', but if you check the backend code logic, then we can find it just use these information and create a JWT for the APP. So for the accessToken API, APP can pass one more parameter push_sid (the current parameter is identity), backend server will parse this push_sid from the APP request, but do not read from env config any more.
Android will pass the FCM push service id and iOS will pass the APN service id, so one server can support both Android and iOS.
You can control through IF/ELSE logic by passing DEVICE TYPE parameter.
public function createTwilioToken($deviceType = 'ANDROID')
{
$twilioAccountSid = config('app.TWILIO_ACCOUNT_SID');
$twilioApiKey = config('app.TWILIO_API_KEY_SID');
$twilioApiSecret = config('app.TWILIO_API_KEY_SECRET');
$conversationId = config('app.TWILIO_CONVERSATIONS_SERVICE_SID');
$androidPushCredentialSid = config('app.TWILIO_PUSH_ANDROID_CREDENTIAL_SID');
$iosPushCredentialSid = config('app.TWILIO_PUSH_IOS_CREDENTIAL_SID');
// choose a random username for the connecting user
$identity = 'USER-IDENTITY';
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$twilioAccountSid,
$twilioApiKey,
$twilioApiSecret,
86400,
$identity
);
// Create Chat grant
$grant = new ChatGrant();
$grant->setServiceSid($conversationId);
if ($deviceType == 'IOS')
{
$grant->setPushCredentialSid($iosPushCredentialSid);
}
else if ($deviceType == 'ANDROID')
{
$grant->setPushCredentialSid($androidPushCredentialSid);
}
// Add grant to token
$token->addGrant($grant);
return $token->toJWT();
}

My android project crashed when I called token.jwt for twilio chat

I am trying to generate access token for twilio chat but got this error:I have been trying to figure out where the error is coming from but can't get it figured out. I will really appreciate your help. Thanks
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zihron.projectmanagementapp, PID: 16355
java.lang.Error: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found
at javax.xml.bind.DatatypeConverterImpl.<clinit>(DatatypeConverterImpl.java:744)
at javax.xml.bind.DatatypeConverter.<clinit>(DatatypeConverter.java:78)
at javax.xml.bind.DatatypeConverter.printBase64Binary(DatatypeConverter.java:547)
at io.jsonwebtoken.impl.Base64Codec.encode(Base64Codec.java:24)
at io.jsonwebtoken.impl.Base64UrlCodec.encode(Base64UrlCodec.java:22)
at
io.jsonwebtoken.impl.AbstractTextCodec.encode(AbstractTextCodec.java:31)
at io.jsonwebtoken.impl.DefaultJwtBuilder.base64UrlEncode(DefaultJwtBuilder.java:314)
at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:282)
at com.twilio.jwt.Jwt.toJwt(Jwt.java:100)
at ZihronChatApp.token.TokenGenerator.getToken(TokenGenerator.java:34)
at com.zihron.projectmanagementapp.ChatActivity.onCreateView(ChatActivity.java:43)
I have my details below:
public AccessToken getToken() {
// Required for all types of tokens
String twilioAccountSid ="AC601f2c7***7ed***640***264c***d0d";
String twilioApiKey = "SK684***dda***c81****6c4a****093**";
String twilioApiSecret ="96****dbc06****b74d50***b9***3*4";
String serviceSid="IS***a29****e24****5d****4b20**3e*";
String identity = "joshua.hamilton#gmail.com";
ChatGrant grant = new ChatGrant();
grant.setServiceSid(serviceSid);
AccessToken token = new AccessToken.Builder(twilioAccountSid,
twilioApiKey, twilioApiSecret)
.identity(identity).grant(grant).build();
Log.e("++==--",""+token.toJwt());
//.identity(identity).grant(grant);
return token;
}
Twilio developer evangelist here.
The Twilio Java library is not intended for use within Android projects.
The issue here is that you should not be storing your credentials within your application. A malicious user could decompile your application, take your credentials and abuse them.
Instead, you should create a server (or use some sort of serverless environment, like Twilio Functions) that can run this code and return the token. You should then make an HTTP request from your Android application to fetch that token. Check out the Twilio Programmable Chat Android Quickstart to see how it's done there.

Automatic Update to Microsoft Graph API Subscription

I have created webhook project with Microsoft Graph API to monitor Office 365 inbox.
I made a UpdateSubscription action method which renews it for 3 days only as according to the documentation provide on https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/subscription
Below is the code snippet of how I'am facilitating the HTTP request to update the subscription
AuthenticationResult authResult = await AuthHelper.GetAccessTokenAsync();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Build the request.
string subscriptionsEndpoint = "https://graph.microsoft.com/v1.0/subscriptions/"+id;
var method = new HttpMethod("PATCH");
HttpRequestMessage request = new HttpRequestMessage(method, subscriptionsEndpoint);
//get the current time
var subscription = new Subscription
{
//Id = id,
ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 4230, 0)
};
Is there a way to auto update without the user pressing the button to 'update'?
since the authorization-headers requires AuthResult.accessToken which will require the user to sign in to Office365 account.
Please advice
An option available to you is the service or daemon approach (https://graph.microsoft.io/en-us/docs/authorization/app_only). Instead of authenticating with a logged-in user you're able to renew the subscription at the application level using a Bearer token which is in turn generated by the CLIENT_SECRET from Azure AD.
I don't think storing tokens in the database is the right approach here. My understanding is that security tokens are never appropriate for a database.
In fact, I don't quite understand the need to have the user log in at all here, unless there are parts to the program that you didn't mention. A service like the one I mentioned can monitor a mailbox without a user being there, or else if the program requires the user to be there, there really isn't an issue of lost credentials.
You can use this approach to fetch accesstoken from azure using grant_type a password. PLease find the below screenshot.

Error:”invalid_grant”, Description:””, Uri:”” while using service account from my local machine

I got below error while using service account from my local machine
Error:
invalid_grant”, Description:””, Uri:””.
see code below -
string[] scopes = new string[] {
AnalyticsService.Scope.Analytics
}; // view and manage your Google Analytics data
var keyFilePath = #
"c:\xxxxxxx.p12"; // Downloaded from https://console.developers.google.com
var serviceAccountEmail = "xxxxx#developer.gserviceaccount.com"; // found https://console.developers.google.com
//loading the Key file
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail) {
Scopes = scopes
}.FromCertificate(certificate));
var service = new AnalyticsService(new BaseClientService.Initializer() {
HttpClientInitializer = credential,
ApplicationName = "Analytics API Sample",
});
string profileId = "xxxxxx";
DataResource.RealtimeResource.GetRequest request = service.Data.Realtime.Get(String.Format("ga:{0}", profileId), "rt:activeUsers");
RealtimeData feed = request.Execute();
invalid_grant has two common causes.
Your server’s clock is not in sync with NTP. (Solution: check the server time if its incorrect fix it. )
The refresh token limit has been exceeded. (Solution: Nothing you can do they cant have more refresh tokens in use)
Applications can request multiple refresh tokens. For example, this is useful in situations where a user wants to install an application on multiple machines. In this case, two refresh tokens are required, one for each installation. When the number of refresh tokens exceeds the limit, older tokens become invalid. If the application attempts to use an invalidated refresh token, an invalid_grant error response is returned. The limit for each unique pair of OAuth 2.0 client and is 25 refresh tokens (note that this limit is subject to change). If the application continues to request refresh tokens for the same Client/Account pair, once the 26th token is issued, the 1st refresh token that was previously issued will become invalid. The 27th requested refresh token would invalidate the 2nd previously issued token and so on.
I have also read of a third which is if you don't include access_type=offline in your request. I have never had an issue with this one myself

Resources