def new_twilio_video_tokens(): # get credentials from config account_sid = 'AC6fbff77992d10662d2d14d9facc494c3' # live_config('TWILIO_ACCOUNT_SID') api_key = 'SK66c0077df076e009565295cd006c0925' #live_config('TWILIO_API_KEY') api_secret = '73w1nYUgPH0sI2KZtgp7qFlSGDGjgn8n' #live_config('TWILIO_API_SECRET') profile_id = 'VSace2c5699219999e4edfcd4b94d7be85' #live_config('TWILIO_CONFIGURATION_SID') id_patient = str(uuid4()) id_clinician = str(uuid4()) # Create an Access Tokens token_patient = AccessToken(account_sid, api_key, api_secret) token_patient.identity = id_patient token_clinician = AccessToken(account_sid, api_key, api_secret) token_clinician.identity = id_clinician # Grant access to Conversations grant = ConversationsGrant() grant.configuration_profile_sid = profile_id token_patient.add_grant(grant) token_clinician.add_grant(grant) # Return token info # we will use the same fields as opentok assuming we will have # only one video provider for a given consult. return { # patient will make the connection so we only keep the clinician id. 'twilio_video_id_clinician': token_clinician.identity, 'twilio_video_token_clinician': token_clinician.to_jwt(), 'twilio_video_id_patient': token_patient.identity, 'twilio_video_token_patient': token_patient.to_jwt(), 'video_provider': 'twilio', }
def token(): if not session.get('logged_in'): return redirect(url_for('login')) else: # get credentials for environment variables account_sid = session.get('sid') print(session.get('sid')) api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] service_sid = os.environ['TWILIO_IPM_SERVICE_SID'] # create a randomly generated username for the client db = get_db() username = session.get('user') identity = username # Create a unique endpoint ID for the device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=service_sid) token.add_grant(ipm_grant) # Return token info as JSON return jsonify(identity=identity, token=token.to_jwt())
def token(request): fake = Factory.create() # get credentials for environment variables # account_sid = os.environ['TWILIO_ACCOUNT_SID'] # api_key = os.environ['TWILIO_API_KEY'] # api_secret = os.environ['TWILIO_API_SECRET'] # service_sid = os.environ['TWILIO_IPM_SERVICE_SID'] account_sid = "ACc8d160e25f25dcd5031b180821428fc0" api_key = "SK05b65992fd32b9b92e6bdb1cd1ea5380" api_secret = "sBsSZAIuGeBtntI8kkly3h6mJk5KfM7S" service_sid = "ISfd35cbde546d43559e194bb240a1e95c" # export TWILIO_ACCOUNT_SID="ACc8d160e25f25dcd5031b180821428fc0" # export TWILIO_API_KEY="SK05b65992fd32b9b92e6bdb1cd1ea5380" # export TWILIO_API_SECRET="sBsSZAIuGeBtntI8kkly3h6mJk5KfM7S" # export TWILIO_IPM_SERVICE_SID="ISfd35cbde546d43559e194bb240a1e95c" # create a randomly generated username for the client identity = fake.user_name() # Create a unique endpoint ID for the device_id = 'broswer' endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=service_sid) token.add_grant(ipm_grant) # Return token info as JSON return JsonResponse({"identity":identity, "token":token.to_jwt()})
def create_video_client(user): # Create identity for the token using random uuid.hex (not to have the hyphens) identity = uuid.uuid4().hex ttl = SHOUTIT_TWILIO_SETTINGS['TOKEN_TTL'] # Create an Access Token token = AccessToken(SHOUTIT_TWILIO_SETTINGS['TWILIO_ACCOUNT_SID'], SHOUTIT_TWILIO_SETTINGS['TWILIO_API_KEY'], SHOUTIT_TWILIO_SETTINGS['TWILIO_API_SECRET'], identity=identity, ttl=ttl) # Grant access to Conversations grant = ConversationsGrant( configuration_profile_sid=SHOUTIT_TWILIO_SETTINGS[ 'TWILIO_CONFIGURATION_SID']) token.add_grant(grant) # Create VideoClient jwt_token = token.to_jwt() video_client = VideoClient.create(id=identity, user=user, token=jwt_token, ttl=ttl) return video_client
def token(request): device_id = request.GET.get('device', 'unknown') identity = request.GET.get('identity', 'guest').encode('utf-8') endpoint_id = "NeighborChat:{0}, {1}".format(device_id, identity) token = AccessToken(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_API_KEY, settings.TWILIO_API_SECRET, identity) grant = IpMessagingGrant() grant.service_sid = settings.TWILIO_IPM_SERVICE_SID grant.endpoint_id = endpoint_id token.add_grant(grant) response = {'identity': identity, 'token': token.to_jwt()} return JsonResponse(response)
def token(): identity = request.args.get('identity') device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) token = AccessToken( constants.TWILIO_ACCOUNT_SID, constants.TWILIO_API_KEY, constants.TWILIO_API_SECRET, identity) ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=constants.TWILIO_SERVICE_SID) token.add_grant(ipm_grant) return jsonify(identity=identity, token=token.to_jwt())
def token(): # get credentials for environment variables account_sid = os.environ['TWILIO_ACCOUNT_SID'] api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] # Create an Access Token token = AccessToken(account_sid, api_key, api_secret) # Set the Identity of this token token.identity = fake.user_name() # Grant access to Conversations grant = ConversationsGrant() grant.configuration_profile_sid = os.environ['TWILIO_CONFIGURATION_SID'] token.add_grant(grant) # Return token info as JSON return jsonify(identity=token.identity, token=token.to_jwt())
def token(): # get credentials for environment variables account_sid = 'ACd9b72d3e2fd1c7afee885f62d2d95a95' api_key = 'SK3a1be8585f189c540584a1757e10ba69' api_secret = 'aNovO6gcHsTOUjByHkUruUHyhq1Aserx' # Create an Access Token token = AccessToken(account_sid, api_key, api_secret) # Set the Identity of this token token.identity = session[secret] # Grant access to Video grant = VideoGrant() grant.configuration_profile_sid = 'VSa37a06ac2dac126260d6675aae39566f' token.add_grant(grant) # Return token info as JSON return jsonify(identity=token.identity, token=token.to_jwt())
def tokens(request): identity = request.user['sub'] endpoint_id = request.GET["endpoint_id"] print("identity: {}\nendpoint: {}".format(identity, endpoint_id)) account_sid = "ACd3a83bf4c0646baaba77cdc355567d1f" api_key = "SK4949cc25487c7bd8001f3e0f21165064" api_secret = "keQ3hukqsJ8PP9WNLs2g6Fels5umPCzM" token = AccessToken(account_sid, api_key, api_secret, identity, ttl=40000) ipm_service_sid = "IS3ba6938016464f7cbcba3d2fea297dca" endpoint_id = ipm_service_sid + identity + endpoint_id push_credential_sid = "CRe9c5eff29e744709d7df875f8a797bf0" ipm_grant = IpMessagingGrant(endpoint_id=endpoint_id, service_sid=ipm_service_sid, push_credential_sid=push_credential_sid) token.add_grant(ipm_grant) return HttpResponse(json.dumps({ 'identity': identity, 'token': token.to_jwt() }))
def get_token(request): account_sid = os.environ['TWILIO_ACCOUNT_SID'] api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] # Create an Access Token token = AccessToken(account_sid, api_key, api_secret) # Set the Identity of this token random_names = [ "Christian Blatter", "Tanaz Kesariwala", "Shanaya Kapoor", "Alisha Chauhan" ] token.identity = random.choice(random_names) # Grant access to Conversations # grant = ConversationsGrant() # grant.configuration_profile_sid = os.environ['TWILIO_CONFIGURATION_SID'] # token.add_grant(grant) # Return token info as JSON return JsonResponse({"identity": token.identity, "token": token.to_jwt()})
def token(): # Hard-coded username of BrowserUser for the client """ Helper function to return a token to the front-end JS IPM client. """ identity = "BrowserUser" # Create a unique endpoint ID for the client device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=TWILIO_IPM_SERVICE_SID) token.add_grant(ipm_grant) # Return token info as JSON return jsonify(identity=identity, token=token.to_jwt())
def token(): # get credentials for environment variables account_sid = os.environ['TWILIO_ACCOUNT_SID'] api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] service_sid = os.environ['TWILIO_IPM_SERVICE_SID'] # create a randomly generated username for the client identity = os.environ['TWILIO_USERNAME'] # Create a unique endpoint ID for the device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=service_sid) token.add_grant(ipm_grant) # Return token info as JSON return jsonify(identity=identity, token=token.to_jwt())
def token(): # get credentials for environment variables account_sid = os.environ['TWILIO_ACCOUNT_SID'] api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] service_sid = os.environ['TWILIO_IPM_SERVICE_SID'] # create a randomly generated username for the client identity = fake.user_name() # Create a unique endpoint ID for the device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=service_sid) token.add_grant(ipm_grant) # Return token info as JSON return jsonify(identity=identity, token=token.to_jwt())
def token(): # get credentials for environment variables account_sid = "ACcdbab0f13e08eb8b19b6d3025a9ad6f7" api_key = "SK2f52e17a9ca74d4714d28a7c575e1e21" api_secret = "6XYHaD6O5zPKDpM4wU34NknCQj7L1d6C" service_sid = "IS27b6d9077d6c48838881fc41b4748bb2" # create a randomly generated username for the client identity = fake.user_name() # Create a unique endpoint ID for the device_id = request.args.get('device') endpoint = "TwilioChatDemo:{0}:{1}".format(identity, device_id) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create an IP Messaging grant and add to token ipm_grant = IpMessagingGrant(endpoint_id=endpoint, service_sid=service_sid) token.add_grant(ipm_grant) # Return token info as JSON return jsonify(identity=identity, token=token.to_jwt())
from twilio.access_token import AccessToken, VoiceGrant # required for all twilio access tokens account_sid = 'ACxxxxxxxxxxxx' api_key = 'SKxxxxxxxxxxxx' api_secret = 'xxxxxxxxxxxxxx' # required for Voice grant outgoing_application_sid = 'APxxxxxxxxxxxxx' identity = 'user' # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity) # Create a Voice grant and add to token voice_grant = VoiceGrant(outgoing_application_sid=outgoing_application_sid) token.add_grant(voice_grant) # Return token info as JSON print(token.to_jwt())
from twilio.access_token import AccessToken # You will need your Account Sid and a SigningKey Sid and Secret # to generate an Access Token for your SDK endpoint to connect to Twilio. account_sid = "{{ account_sid }}" signingkey_sid = SID signingkey_secret = SECRET token = AccessToken(signingkey_sid, account_sid, signingkey_secret) token.add_endpoint_grant(ENDPOINT_ADDRESS) token.enable_nts() print token.to_jwt()