Twilio 视频 + 解析
Twilio Video + Parse
我正在使用 Twilio-Video 构建应用程序 (https://www.twilio.com/docs/api/video)。我用解析做了 usermanagement-Database,但我有访问令牌的问题。
当我的用户在我的应用程序中注册时,我想将 twilio 访问令牌分配给他们的用户名 - 问题是我该怎么做?还是无法解析?我的应用程序需要额外的后端服务器吗?我有点困惑。
https://www.twilio.com/docs/api/video/guide/identity
谢谢!
这里是 Twilio 开发人员布道者。
正如您提到的,您在 Heroku 上使用 Parse 服务器,我相信我可以提供帮助!
当用户注册您的应用程序时,您实际上并不想为 Twilio Video 创建访问令牌。令牌是可配置的,最多可以持续 24 小时。所以您想在用户需要时生成令牌。
解析服务器是一个基于 Node.js 的服务器,can be embedded within an Express server. Once you do that you can then install the latest Twilio npm module 并使用它从 Express 端点为您的用户生成令牌。
生成令牌所需的代码看起来有点像这样:
var AccessToken = require('twilio').AccessToken;
var IpMessagingGrant = AccessToken.IpMessagingGrant;
// Used when generating any kind of tokens
var twilioAccountSid = 'ACxxxxxxxxxx';
var twilioApiKey = 'SKxxxxxxxxxx';
var twilioApiSecret = 'xxxxxxxxxxxx';
// Used specifically for creating IP Messaging tokens
var serviceSid = 'ISxxxxxxxxxxxxx';
var appName = 'HipFlowSlackDockRC';
var identity = 'user@example.com';
var deviceId = 'someiosdeviceid';
var endpointId = appName + ':' + identity + ':' + deviceId;
// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
serviceSid: serviceSid,
endpointId: endpointId
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(ipmGrant);
token.identity = identity;
// Serialize the token to a JWT string
console.log(token.toJwt());
// For your app you want to return the token to the front end somehow.
有关详细信息,请查看 Twilio API reference for creating access tokens。
我正在使用 Twilio-Video 构建应用程序 (https://www.twilio.com/docs/api/video)。我用解析做了 usermanagement-Database,但我有访问令牌的问题。
当我的用户在我的应用程序中注册时,我想将 twilio 访问令牌分配给他们的用户名 - 问题是我该怎么做?还是无法解析?我的应用程序需要额外的后端服务器吗?我有点困惑。
https://www.twilio.com/docs/api/video/guide/identity
谢谢!
这里是 Twilio 开发人员布道者。
正如您提到的,您在 Heroku 上使用 Parse 服务器,我相信我可以提供帮助!
当用户注册您的应用程序时,您实际上并不想为 Twilio Video 创建访问令牌。令牌是可配置的,最多可以持续 24 小时。所以您想在用户需要时生成令牌。
解析服务器是一个基于 Node.js 的服务器,can be embedded within an Express server. Once you do that you can then install the latest Twilio npm module 并使用它从 Express 端点为您的用户生成令牌。
生成令牌所需的代码看起来有点像这样:
var AccessToken = require('twilio').AccessToken;
var IpMessagingGrant = AccessToken.IpMessagingGrant;
// Used when generating any kind of tokens
var twilioAccountSid = 'ACxxxxxxxxxx';
var twilioApiKey = 'SKxxxxxxxxxx';
var twilioApiSecret = 'xxxxxxxxxxxx';
// Used specifically for creating IP Messaging tokens
var serviceSid = 'ISxxxxxxxxxxxxx';
var appName = 'HipFlowSlackDockRC';
var identity = 'user@example.com';
var deviceId = 'someiosdeviceid';
var endpointId = appName + ':' + identity + ':' + deviceId;
// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
serviceSid: serviceSid,
endpointId: endpointId
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(ipmGrant);
token.identity = identity;
// Serialize the token to a JWT string
console.log(token.toJwt());
// For your app you want to return the token to the front end somehow.
有关详细信息,请查看 Twilio API reference for creating access tokens。