Exemple #1
0
def generateTwilioAccessToken(sender, **kwargs):
    print "user_logged_in receiver"
    print sender
    print kwargs['request']
    user = kwargs['user']

    try:
        doctor = user.doctor

        # create a randomly generated username for the client
        identity = user.username

        # <unique app>:<user>:<device>
        endpoint = "PalliAssist:" + identity + ":web"

        # Create access token with credentials
        token = AccessToken(settings.TWILIO_ACCOUNT_SID,
                            settings.TWILIO_API_KEY,
                            settings.TWILIO_API_SECRET, identity)

        # Create an IP Messaging grant and add to token
        ipm_grant = IpMessagingGrant(
            endpoint_id=endpoint, service_sid=settings.TWILIO_IPM_SERVICE_SID)
        token.add_grant(ipm_grant)

        doctor.twilio_token = token
        doctor.save()

        print doctor.twilio_token

    except Doctor.DoesNotExist:
        print "error. not a doctor logging in?"
Exemple #2
0
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 get_accesstoken(self):
        """
        # This function builds jwt of access token with username
        """
        # Select sid from t1, according userid and classid
        sid = self.check_access()
        # Select authtoken, apikey, secret fro table t0.
        infoacc = Subaccount.query.filter_by(id=sid).all()
        users = Users.query.filter_by(id=self.userid).all()

        # Substitute your Twilio AccountSid and ApiKey details
        ACCOUNT_SID = sid
        API_KEY_SID = infoacc[0].apikey
        API_KEY_SECRET = infoacc[0].apisecret
        CONFIGURATION_SID = infoacc[0].configid

        # Create an Access Token
        token = AccessToken(ACCOUNT_SID, API_KEY_SID, API_KEY_SECRET)

        # Set the Identity of this  token
        username = users[0].name
        token.identity = username

        # Grant access to Conversations
        grant = ConversationsGrant()
        grant.configuration_profile_sid = CONFIGURATION_SID
        token.add_grant(grant)
        # Return token info as JSON
        return token
Exemple #4
0
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',
    }
Exemple #5
0
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())
Exemple #6
0
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 test_conversations_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, "secret")
        scat.add_grant(ConversationsGrant())

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, "secret")
        self._validate_claims(payload)
        assert_equal(1, len(payload["grants"]))
        assert_equal({}, payload["grants"]["rtc"])
Exemple #8
0
 def test_single_grant(self):
     scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
     scat.add_grant('https://api.twilio.com/**')
     token = str(scat)
     assert_is_not_none(token)
     payload = decode(token, 'secret')
     self._validate_claims(payload)
     assert_equal(1, len(payload['grants']))
     assert_equal('https://api.twilio.com/**', payload['grants'][0]['res'])
     assert_equal(['*'], payload['grants'][0]['act'])
    def test_ip_messaging_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, "secret")
        scat.add_grant(IpMessagingGrant())

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, "secret")
        self._validate_claims(payload)
        assert_equal(1, len(payload["grants"]))
        assert_equal({}, payload["grants"]["ip_messaging"])
Exemple #10
0
 def test_endpoint_grant(self):
     scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
     scat.add_endpoint_grant('bob')
     token = str(scat)
     assert_is_not_none(token)
     payload = decode(token, 'secret')
     self._validate_claims(payload)
     assert_equal(1, len(payload['grants']))
     assert_equal('sip:[email protected]',
                  payload['grants'][0]['res'])
     assert_equal(['listen', 'invite'], payload['grants'][0]['act'])
Exemple #11
0
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)
Exemple #12
0
    def test_conversations_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({'configuration_profile_sid': 'CP123'},
                     payload['grants']['rtc'])
Exemple #13
0
 def test_enable_nts(self):
     scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
     scat.enable_nts()
     token = str(scat)
     assert_is_not_none(token)
     payload = decode(token, 'secret')
     self._validate_claims(payload)
     assert_equal(1, len(payload['grants']))
     assert_equal('https://api.twilio.com/2010-04-01/Accounts/AC123/Tokens.json',
                  payload['grants'][0]['res'])
     assert_equal(['POST'], payload['grants'][0]['act'])
Exemple #14
0
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 test_conversations_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({
            'configuration_profile_sid': 'CP123'
        }, payload['grants']['rtc'])
    def test_grants(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(ConversationsGrant())
        scat.add_grant(IpMessagingGrant())

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(2, len(payload['grants']))
        assert_equal({}, payload['grants']['rtc'])
        assert_equal({}, payload['grants']['ip_messaging'])
    def test_sync_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(SyncGrant(service_sid='IS123', endpoint_id='some-endpoint'))

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({
            'service_sid': 'IS123',
            'endpoint_id': 'some-endpoint'
        }, payload['grants']['data_sync'])
Exemple #18
0
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 test_ip_messaging_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(IpMessagingGrant(service_sid='IS123', push_credential_sid='CR123'))

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({
            'service_sid': 'IS123',
            'push_credential_sid': 'CR123'
        }, payload['grants']['ip_messaging'])
    def test_ip_messaging_grant(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(IpMessagingGrant(service_sid='IS123', push_credential_sid='CR123'))

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({
            'service_sid': 'IS123',
            'push_credential_sid': 'CR123'
        }, payload['grants']['ip_messaging'])
Exemple #21
0
 def test_empty_grants(self):
     scat = AccessToken(SIGNING_KEY_SID, ACCOUNT_SID, 'secret')
     token = str(scat)
     assert_is_not_none(token)
     payload = decode(token, 'secret')
     self._validate_claims(payload)
     assert_equal([], payload['grants'])
Exemple #22
0
def twilio_token():
    # get credentials for environment variables
    account_sid = current_app.config['TWILIO_ACCOUNT_SID']
    api_key = current_app.config['TWILIO_API_KEY']
    api_secret = current_app.config['TWILIO_API_SECRET']

    # Create an Access Token
    token = AccessToken(account_sid, api_key, api_secret)

    # Grant access to Conversations
    grant = ConversationsGrant()
    grant.configuration_profile_sid = current_app.config[
        'TWILIO_CONFIGURATION_SID']
    token.add_grant(grant)

    return token
Exemple #23
0
    def test_nbf(self):
        now = int(time.mktime(datetime.now().timetuple()))
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', nbf=now)
        token = str(scat)

        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(now, payload['nbf'])
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 test_identity(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', identity='*****@*****.**')
        token = str(scat)

        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal({
            'identity': '*****@*****.**'
        }, payload['grants'])
Exemple #26
0
    def test_programmable_voice_grant(self):
        grant = VoiceGrant(outgoing_application_sid='AP123',
                           outgoing_application_params={'foo': 'bar'})

        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(grant)

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal(
            {
                'outgoing': {
                    'application_sid': 'AP123',
                    'params': {
                        'foo': 'bar'
                    }
                }
            }, payload['grants']['voice'])
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()
    }))
Exemple #28
0
    def test_grants(self):
        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(ConversationsGrant())
        scat.add_grant(IpMessagingGrant())
        scat.add_grant(VideoGrant())

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(3, len(payload['grants']))
        assert_equal({}, payload['grants']['rtc'])
        assert_equal({}, payload['grants']['ip_messaging'])
        assert_equal({}, payload['grants']['video'])
Exemple #29
0
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()})
Exemple #30
0
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 = 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())
Exemple #32
0
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())
Exemple #33
0
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())
    def test_programmable_voice_grant(self):
        grant = VoiceGrant(
            outgoing_application_sid='AP123',
            outgoing_application_params={
                'foo': 'bar'
            }
        )

        scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
        scat.add_grant(grant)

        token = str(scat)
        assert_is_not_none(token)
        payload = decode(token, 'secret')
        self._validate_claims(payload)
        assert_equal(1, len(payload['grants']))
        assert_equal({
            'outgoing': {
                'application_sid': 'AP123',
                'params': {
                    'foo': 'bar'
                }
            }
        }, payload['grants']['voice'])
Exemple #35
0
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())
Exemple #36
0
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())
from twilio.access_token import AccessToken, VideoGrant

# required for all twilio access tokens
account_sid = 'ACxxxxxxxxxxxx'
api_key = 'SKxxxxxxxxxxxx'
api_secret = 'xxxxxxxxxxxxxx'

# required for Video grant
configuration_profile_sid = 'VSxxxxxxxxxxxx'
identity = 'user'

# Create access token with credentials
token = AccessToken(account_sid, api_key, api_secret, identity)

# Create a Video grant and add to token
video_grant = VideoGrant(configuration_profile_sid=configuration_profile_sid)
token.add_grant(video_grant)

# Return token info as JSON
print(token.to_jwt())
Exemple #38
0
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()
Exemple #39
0
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, IpMessagingGrant

# required for all twilio access tokens
account_sid = 'ACxxxxxxxxxxxx'
api_key = 'SKxxxxxxxxxxxx'
api_secret = 'xxxxxxxxxxxxxx'

# required for IP messaging grants
ipm_service_sid = 'ISxxxxxxxxxxxx'
identity = '*****@*****.**'
device_id = 'someiosdevice'
endpoint_id = "HipFlowSlackDockRC:{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_id, service_sid=ipm_service_sid)
token.add_grant(ipm_grant)

# Return token info as JSON
print(token.to_jwt())