Пример #1
0
        public async Task <IActionResult> PostChatToken([FromForm] string identity = "Joe")
        {
            _logger.LogInformation("Getting the access token");

            if (!IsValidServiceSettings(_twilioServiceSettings))
            {
                var exception = new ApplicationException("Twilio Service Settings are not set correctly. Double check and retry your operation again");
                _logger.LogError(exception, $"{nameof(_twilioServiceSettings)} are not setting correctly");
                throw exception;
            }

            if (!IsValidSettings(_twilioSettings))
            {
                var exception = new ApplicationException("Twilio Settings are not set correctly. Double check and retry your operation again");
                _logger.LogError(exception, $"{nameof(_twilioSettings)} are not setting correctly");
                throw exception;
            }

            var chatGrant = new ChatGrant
            {
                ServiceSid = _twilioServiceSettings.ServiceSid
            };

            var hashGrants = new HashSet <IGrant> {
                { chatGrant }
            };

            var token = new Token(_twilioSettings.AccountSid, _twilioServiceSettings.ApiKey, _twilioServiceSettings.ApiSecret, identity, grants: hashGrants);

            _logger.LogInformation("Got access token", token.ToJwt());

            return(await Task.FromResult(new ContentResult { Content = token.ToJwt(), ContentType = "application/jwt", StatusCode = 200 }));
        }
        public IActionResult Get([FromQuery] string identity)
        {
            // These values are necessary for any access token
            string twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
            string twilioApiKey     = Environment.GetEnvironmentVariable("TWILIO_API_KEY");
            string twilioApiSecret  = Environment.GetEnvironmentVariable("TWILIO_API_SECRET");

            // These are specific to Chat
            const string serviceSid = "IS47f596cddbf34ce49490ef4af838bd07";

            // Create an Chat grant for this token

            var grant = new ChatGrant
            {
                ServiceSid = serviceSid
            };

            var grants = new HashSet <IGrant>
            {
                { grant }
            };

            // Create an Access Token generator
            var token = new Token(
                twilioAccountSid,
                twilioApiKey,
                twilioApiSecret,
                identity,
                grants: grants);

            return(new JsonContent(new { token = token.ToJwt() }));
        }
Пример #3
0
    static void Main(string[] args)
    {
        // These values are necessary for any access token
        const string twilioAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string twilioApiKey     = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string twilioApiSecret  = "your_secret";

        // These are specific to Chat
        const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string identity   = "*****@*****.**";
        const string deviceId   = "someiosdevice";

        // Create an Chat grant for this token

        var grant = new ChatGrant
        {
            ServiceSid = serviceSid,
            EndpointId = $"HipFlowSlackDockRC:{identity}:{deviceId}"
        };

        var grants = new HashSet <IGrant>
        {
            { grant }
        };

        // Create an Access Token generator
        var token = new Token(
            twilioAccountSid,
            twilioApiKey,
            twilioApiSecret,
            identity,
            grants: grants);

        Console.WriteLine(token.ToJwt());
    }
Пример #4
0
    static void Main(string[] args)
    {
        // These values are necessary for any access token
        // To set up environmental variables, see http://twil.io/secure
        const string twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string twilioApiKey     = Environment.GetEnvironmentVariable("TWILIO_API_KEY");
        const string twilioApiSecret  = Environment.GetEnvironmentVariable("TWILIO_API_SECRET");

        // These are specific to Chat
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");
        const string identity   = "*****@*****.**";

        // Create an Chat grant for this token

        var grant = new ChatGrant
        {
            ServiceSid = serviceSid
        };

        var grants = new HashSet <IGrant>
        {
            { grant }
        };

        // Create an Access Token generator
        var token = new Token(
            twilioAccountSid,
            twilioApiKey,
            twilioApiSecret,
            identity,
            grants: grants);

        Console.WriteLine(token.ToJwt());
    }
Пример #5
0
        public Task <string> Generate(string identity, string endpointId)
        {
            var grants = new HashSet <IGrant>();

            if (_account.ChatServiceSid != string.Empty)
            {
                var chatGrant = new ChatGrant
                {
                    ServiceSid = _account.ChatServiceSid,
                    EndpointId = endpointId
                };

                grants.Add(chatGrant);
            }

            var token = new Token(
                _account.AccountSid,
                _account.ApiKey,
                _account.ApiSecret,
                identity,
                grants: grants
                ).ToJwt();

            return(Task.FromResult(token));
        }
        public JsonResult Token()
        {
            // This can be tracked internally by your web app.
            var identity = randomUserId();


            var grants = new HashSet <IGrant>();

            var videoGrant = new VideoGrant();

            grants.Add(videoGrant);

            if (_appSettings.TWILIO_CHAT_SERVICE_SID != String.Empty)
            {
                // Create a "grant" which enables a client to use IPM as a given user,
                // on a given device.
                var chatGrant = new ChatGrant()
                {
                    ServiceSid = _appSettings.TWILIO_CHAT_SERVICE_SID,
                };

                grants.Add(chatGrant);
            }

            if (_appSettings.TWILIO_SYNC_SERVICE_SID != String.Empty)
            {
                var syncGrant = new SyncGrant()
                {
                    ServiceSid = _appSettings.TWILIO_SYNC_SERVICE_SID
                };

                grants.Add(syncGrant);
            }

            var token = new Token(
                _appSettings.TWILIO_ACCOUNT_SID,
                _appSettings.TWILIO_API_KEY,
                _appSettings.TWILIO_API_SECRET,
                identity,
                grants: grants
                ).ToJwt();

            return(new JsonResult(new Dictionary <string, string>()
            {
                { "identity", identity },
                { "token", token }
            }));
        }
        private JsonResult CreateTokenResult(string identity)
        {
            var grants = new HashSet <IGrant>();

            var videoGrant = new VideoGrant();

            grants.Add(videoGrant);

            if (_twilioAccount.ChatServiceSid != String.Empty)
            {
                // Create a "grant" which enables a client to use IPM as a given user,
                // on a given device.
                var chatGrant = new ChatGrant()
                {
                    ServiceSid = _twilioAccount.ChatServiceSid
                };

                grants.Add(chatGrant);
            }

            if (_twilioAccount.SyncServiceSid != String.Empty)
            {
                var syncGrant = new SyncGrant()
                {
                    ServiceSid = _twilioAccount.SyncServiceSid
                };

                grants.Add(syncGrant);
            }

            var token = new Token(

                _twilioAccount.AccountSid,
                _twilioAccount.ApiKey,
                _twilioAccount.ApiSecret,
                identity,
                grants: grants
                ).ToJwt();

            return(new JsonResult(new Dictionary <string, string>()
            {
                { "identity", identity },
                { "token", token }
            }));
        }
Пример #8
0
        public Task <string> Generate(string identity)
        {
            var grants = new HashSet <IGrant>();

            var videoGrant = new VideoGrant();

            grants.Add(videoGrant);

            if (_account.ChatServiceSid != string.Empty)
            {
                var chatGrant = new ChatGrant()
                {
                    ServiceSid = _account.ChatServiceSid,
                };

                grants.Add(chatGrant);
            }

            if (_account.SyncServiceSid != string.Empty)
            {
                var syncGrant = new SyncGrant()
                {
                    ServiceSid = _account.SyncServiceSid
                };

                grants.Add(syncGrant);
            }

            var token = new Token(
                _account.AccountSid,
                _account.ApiKey,
                _account.ApiSecret,
                identity,
                grants: grants
                ).ToJwt();

            return(Task.FromResult(token));
        }
Пример #9
0
        public static async Task <string> GetTokenAsync()
        {
            var          deviceId         = CrossDeviceInfo.Current.Id;
            const string twilioAccountSid = "AC3b4d9037a04f31c8e64fcd02ff2c6a9d";
            const string twilioApiKey     = "SK797d3f329ea89c8d0a5eb7a27d92274d";
            const string twilioApiSecret  = "B8mbBv19bFxRYZFv75dUFbmSsINeOd1x";

            var identity        = "Syncfusion";
            var applicationName = "AndroidChatApplication";
            var device          = deviceId;

            var endpointId = string.Format("{0}:{1}:{2}", applicationName, identity, device);

            // Create an Chat grant for this token
            var grant = new ChatGrant
            {
                EndpointId = endpointId,
                ServiceSid = "ISc9730136ea654f0bad6cf664c659e753"
            };


            var grants = new HashSet <IGrant>
            {
                { grant }
            };

            // Create an Access Token generator
            var token = new Token(
                twilioAccountSid,
                twilioApiKey,
                twilioApiSecret,
                identity,
                grants: grants);

            return(token.ToJwt());
        }