def get_token(): capability = ClientCapabilityToken(TWILIO_SID, TWILIO_TOKEN) capability.allow_client_outgoing(TWILIO_TWIML_SID) capability.allow_client_incoming(default_client) token = capability.to_jwt() # encoded = base64.encodestring(token) return token
def audio(campaign_id): campaign = Campaign.query.filter_by(id=campaign_id).first_or_404() form = CampaignAudioForm() twilio_client = current_app.config.get('TWILIO_CLIENT') twilio_capability = ClientCapabilityToken(*twilio_client.auth) twilio_capability.allow_client_outgoing( current_app.config.get('TWILIO_PLAYBACK_APP')) for field in form: campaign_audio, is_default_message = campaign.audio_or_default( field.name) if not is_default_message: field.data = campaign_audio if form.validate_on_submit(): form.populate_obj(campaign) db.session.add(campaign) db.session.commit() flash('Campaign audio updated.', 'success') return redirect(url_for('campaign.launch', campaign_id=campaign.id)) return render_template( 'campaign/audio.html', campaign=campaign, form=form, twilio_capability=twilio_capability.to_jwt().decode('UTF-8'), descriptions=current_app.config.CAMPAIGN_FIELD_DESCRIPTIONS, example_text=current_app.config.CAMPAIGN_MESSAGE_DEFAULTS)
def generate_view(charset='utf-8'): worker_sid = request.args.get('WorkerSid') # TaskRouter Worker Token worker_capability = WorkerCapabilityToken( account_sid=account_sid, auth_token=auth_token, workspace_sid=workspace_sid, worker_sid=worker_sid) # generate worker capability token worker_capability.allow_update_activities( ) # allow agent to update their activity status e.g. go offline worker_capability.allow_update_reservations( ) # allow agents to update reservations e.g. accept/reject worker_token = worker_capability.to_jwt(ttl=28800) capability = ClientCapabilityToken( account_sid, auth_token) # agent Twilio Client capability token capability.allow_client_outgoing(twiml_app) capability.allow_client_incoming(worker_sid) client_token = capability.to_jwt() # render client/worker tokens to the agent desktop so that they can be queried on the client side return render_template('agent_desktop.html', token=client_token.decode("utf-8"), worker_token=worker_token.decode("utf-8"), client_=worker_sid, activity=activity, caller_id=caller_id)
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console account_sid = 'ASID' auth_token = 'ATOKEN' capability = ClientCapabilityToken(account_sid, auth_token) # Twilio Application Sid application_sid = 'AP2439c31dd3d2b5604f3d795d40bfb97c' capability.allow_client_outgoing(application_sid) capability.allow_client_incoming('ValerieTest') token = capability.to_jwt() print(capability.to_jwt()) return Response(token, mimetype='application/jwt')
def test_pass_scopes_in_constructor(self): token = ClientCapabilityToken('AC123', 'XXXXX', allow_client_outgoing={ 'application_sid': 'AP123', 'param1': 'val1' }) outgoing_uri = "scope:client:outgoing?appParams=param1%3Dval1&appSid=AP123" result = Jwt.from_jwt(token.to_jwt(), "XXXXX") self.assertEqual(outgoing_uri, result.payload["scope"])
def get_token(request): capability = ClientCapabilityToken( settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID) capability.allow_client_incoming('general') token = capability.to_jwt() return JsonResponse({'token': token.decode('utf-8')})
def get_capability_token(): account_sid = config.config_tree['twilio']['account_sid'] auth_token = config.config_tree['twilio']['auth_token'] application_sid = config.config_tree['twilio']['webrtc_sid'] capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_outgoing(application_sid) token = capability.to_jwt() return token.decode("utf-8")
def client(): """Respond to incoming requests.""" client_name = request.values.get('client', None) or "TomPY" account_sid = os.environ.get("Twilio_account_sid") auth_token = os.environ.get("Twilio_auth_token") # This is a special Quickstart application sid - or configure your own # at twilio.com/user/account/apps application_sid = os.environ.get("Twilio_application_sid") capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_outgoing(application_sid) capability.allow_client_incoming(client_name) token = capability.to_jwt() print(capability.to_jwt()) return render_template('index.html', token=token.decode("utf-8"), client_name=client_name)
def capability_token(): account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['AUTH_TOKEN'] application_sid = os.environ['APPLICATION_SID'] capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_outgoing(application_sid) print(capability) token = capability.to_jwt() return jsonify(token=token.decode('utf-8'))
def get_token(request): """Returns a Twilio Client token""" # Create a TwilioCapability token with our Twilio API credentials capability = ClientCapabilityToken(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) capability.allow_client_outgoing(settings.TWILIO_ACCOUNT_SID) capability.allow_client_incoming('support_agent') token = capability.to_jwt() return JsonResponse({'token': token.decode('utf-8')})
def generate(agent_id): account_sid = ENV['TWILIO_ACCOUNT_SID'] auth_token = ENV['TWILIO_AUTH_TOKEN'] capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_incoming(agent_id) jwt = capability.to_jwt() try: jwt_str = jwt.decode('utf-8') except Exception as e: jwt_str = jwt return jwt_str
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_incoming("joey") token = capability.to_jwt() return Response(token, mimetype='application/jwt')
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console # To set up environmental variables, see http://twil.io/secure account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_incoming("joey") token = capability.to_jwt() return Response(token, mimetype='application/jwt')
def token(): print(request.args) if request.args.get('identity'): identity = request.args.get('identity') else: identity = alphanumeric_only.sub('', fake.user_name()) # Create a Capability Token capability = ClientCapabilityToken(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) capability.allow_client_outgoing(TWILIO_TWIML_APP_SID) capability.allow_client_incoming(identity) token = capability.to_jwt() # Return token info as JSON return jsonify(identity=identity, token=token.decode('utf-8'))
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console account_sid = 'ACab62879858e561e0bee754b4beb4363f' auth_token = '09eddc4f6d8fc25860589d648f1f5fa8' capability = ClientCapabilityToken(account_sid, auth_token) # Twilio Application Sid application_sid = 'AP32bea3e2b14a2063a3bbc7fe36489eb3' capability.allow_client_outgoing(application_sid) capability.allow_client_incoming('joey') token = capability.to_jwt() return Response(token, mimetype='application/jwt')
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console account_sid = 'ACf2d4b74b4b25771e647846fd049d58fa' auth_token = 'c0e421d575b7c12c28434af8b9c02d79' capability = ClientCapabilityToken(account_sid, auth_token) # Twilio Application Sid application_sid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' capability.allow_client_outgoing(application_sid) capability.allow_client_incoming('joey') token = capability.to_jwt() return Response(token, mimetype='application/jwt')
def get_voice_token(username): logger.info(f'Generating Voice token for {username}') token = ClientCapabilityToken(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) token.allow_client_incoming(username) # Expire token in three minutes expiration = 180 jwt_token = token.to_jwt(ttl=expiration).decode("utf-8") # Cache the token, set to expire after the token expires cache.set(f'tokens:voice:{username}', jwt_token, expiration) return jwt_token
def test_decode(self): token = ClientCapabilityToken("AC123", "XXXXX") token.allow_client_outgoing("AP123", foobar=3) token.allow_client_incoming("andy") token.allow_event_stream() outgoing_uri = "scope:client:outgoing?appParams=foobar%3D3&appSid=AP123&clientName=andy" incoming_uri = "scope:client:incoming?clientName=andy" event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents" result = Jwt.from_jwt(token.to_jwt(), "XXXXX") scope = result.payload["scope"].split(" ") self.assertIn(outgoing_uri, scope) self.assertIn(incoming_uri, scope) self.assertIn(event_uri, scope)
def get_capability_token(): """Respond to incoming requests.""" # Find these values at twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' capability = ClientCapabilityToken(account_sid, auth_token) # Twilio Application Sid application_sid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' capability.allow_client_outgoing(application_sid) capability.allow_client_incoming(request.form["ClientName"]) token = capability.to_jwt() return Response(token, mimetype='application/jwt')
def token(): # get credentials for environment variables account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] application_sid = os.environ['TWILIO_TWIML_APP_SID'] # Generate a random user name identity = alphanumeric_only.sub('', fake.user_name()) # Create a Capability Token capability = ClientCapabilityToken(account_sid, auth_token) capability.allow_client_outgoing(application_sid) capability.allow_client_incoming(identity) token = capability.to_jwt() # Return token info as JSON return jsonify(identity=identity, token=token.decode('utf-8'))
def get_token(request): """Returns a Twilio Client token""" # Create a TwilioCapability token with our Twilio API credentials capability = ClientCapabilityToken( settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) # If the user is on the support dashboard page, we allow them to accept # incoming calls to "support_agent" # (in a real app we would also require the user to be authenticated) capability.allow_client_incoming(request.user.username) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID) # Generate the capability token token = capability.to_jwt() return JsonResponse({'token': token})
def get_token(request): """Returns a Twilio Client token""" # Create a TwilioCapability token with our Twilio API credentials capability = ClientCapabilityToken( settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN ) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID) if request.user.groups.filter(name="Comprendre").exists(): capability.allow_client_incoming('understand_user') else: capability.allow_client_incoming('awareness_user') # Generate the capability token token = capability.to_jwt() return JsonResponse({'token': token.decode('utf-8')})
def get_token(): """Returns a Twilio Client token""" # Create a TwilioCapability object with our Twilio API credentials capability = ClientCapabilityToken(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(app.config['TWIML_APPLICATION_SID']) # If the user is on the support dashboard page, we allow them to accept # incoming calls to "support_agent" # (in a real app we would also require the user to be authenticated) if request.args.get('forPage') == '/dashboard': capability.allow_client_incoming('support_agent') else: # Otherwise we give them a name of "customer" capability.allow_client_incoming('customer') # Generate the capability token token = capability.to_jwt() return jsonify({'token': token})
def get_token(request): """Returns a Twilio Client token""" # Create a TwilioCapability token with our Twilio API credentials capability = ClientCapabilityToken(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(settings.TWIML_APP_SID_BROWSERCALL) # If the user is on the support dashboard page, we allow them to accept # incoming calls to "sales_rep" # (in a real app we would also require the user to be authenticated) if request.GET['forPage'] == reverse('call_tracking:recent-activity'): capability.allow_client_incoming('sales_rep') else: # Otherwise we give them a name of "lead" capability.allow_client_incoming('lead') # Generate the capability token token = capability.to_jwt() return JsonResponse({'token': token.decode('utf-8')})
def get_token(request): """Returns a Twilio Client token""" # Create a TwilioCapability token with our Twilio API credentials capability = ClientCapabilityToken(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID) # If the user is on the support dashboard page, we allow them to accept # incoming calls to "support_agent" # (in a real app we would also require the user to be authenticated) if request.GET['forPage'] == reverse('dashboard'): capability.allow_client_incoming('support_agent') else: # Otherwise we give them a name of "customer" capability.allow_client_incoming('customer') # Generate the capability token token = capability.to_jwt().decode("utf-8") return JsonResponse({'token': token})
def get_token(): """Returns a Twilio Client token""" # Create a TwilioCapability object with our Twilio API credentials capability = ClientCapabilityToken( app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']) # Allow our users to make outgoing calls with Twilio Client capability.allow_client_outgoing(app.config['TWIML_APPLICATION_SID']) # If the user is on the support dashboard page, we allow them to accept # incoming calls to "support_agent" # (in a real app we would also require the user to be authenticated) if request.args.get('forPage') == '/dashboard': capability.allow_client_incoming('support_agent') else: # Otherwise we give them a name of "customer" capability.allow_client_incoming('customer') # Generate the capability token token = capability.to_jwt() return jsonify({'token': token})
def call_token(): capability = ClientCapabilityToken(*CREDS) capability.allow_client_outgoing(conf.creds.tw_ml_app) return capability.to_jwt()