deploying functions and getting token works
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export default class TwilioAccessToken {
|
||||
constructor(public token: string) {}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as functions from 'firebase-functions';
|
||||
import * as twilio from 'twilio';
|
||||
|
||||
import TwilioAccessToken from '../../../core/src/functions/response/TwilioAccessToken.response';
|
||||
import TwilioAccessToken from './core/functions/response/TwilioAccessToken.response';
|
||||
|
||||
const AccessToken = twilio.jwt.AccessToken;
|
||||
// // Start writing Firebase Functions
|
||||
@@ -18,31 +18,36 @@ export const helloWorld = functions.https.onRequest((request, response) => {
|
||||
export const getStreamToken = functions.https.onCall((data, context) => {
|
||||
// Used when generating any kind of tokens
|
||||
// To set up environmental variables, see http://twil.io/secure
|
||||
const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID;
|
||||
const twilioApiKey = process.env.TWILIO_API_KEY;
|
||||
const twilioApiSecret = process.env.TWILIO_API_SECRET;
|
||||
try {
|
||||
const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID;
|
||||
const twilioApiKey = process.env.TWILIO_API_KEY;
|
||||
const twilioApiSecret = process.env.TWILIO_API_SECRET;
|
||||
|
||||
if (!twilioAccountSid || !twilioApiKey || !twilioApiSecret) {
|
||||
functions.logger.error('no twilio access tokens!!!');
|
||||
if (!twilioAccountSid || !twilioApiKey || !twilioApiSecret) {
|
||||
functions.logger.error('no twilio access tokens!!!');
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
const identity = 'user';
|
||||
|
||||
// Create Video Grant
|
||||
const videoGrant = new VideoGrant();
|
||||
|
||||
// Create an access token which we will sign and return to the client,
|
||||
// containing the grant we just created
|
||||
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret, {
|
||||
identity: identity,
|
||||
});
|
||||
|
||||
token.addGrant(videoGrant);
|
||||
|
||||
functions.logger.info(`${context.auth?.uid} user granted a stream access token`);
|
||||
|
||||
// Serialize the token to a JWT string
|
||||
return new TwilioAccessToken(token.toJwt());
|
||||
} catch (error) {
|
||||
functions.logger.error(error);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const identity = 'user';
|
||||
|
||||
// Create Video Grant
|
||||
const videoGrant = new VideoGrant();
|
||||
|
||||
// Create an access token which we will sign and return to the client,
|
||||
// containing the grant we just created
|
||||
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret, {
|
||||
identity: identity,
|
||||
});
|
||||
|
||||
token.addGrant(videoGrant);
|
||||
|
||||
functions.logger.info(`${context.auth?.uid} user granted a stream access token`);
|
||||
|
||||
// Serialize the token to a JWT string
|
||||
return new TwilioAccessToken(token.toJwt());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user