Skip to content

Commit 8612f45

Browse files
patillacodedprothero
authored andcommitted
DEVED-3719: authentication with api key and api secret (TwilioDevEd#752)
* Added snippets for authentication with api key and secret * Modify meta.json * Added proof request. Fix Java indent. * Fix comments * Edited meta.json and renamed files to work correctly with tricorder * Added insecure message
1 parent 06b657e commit 8612f45

7 files changed

+128
-0
lines changed

api-auth/api-auth.3.x.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const twilio = require('twilio');
2+
3+
const myAccountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your Account SID from www.twilio.com/console
4+
const apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // You can generate this from www.twilio.com/console/runtime/api-keys/create
5+
const apiSecret = 'your_api_secret'; // You can generate this from www.twilio.com/console/runtime/api-keys/create
6+
7+
// DANGER! This is insecure. See http://twil.io/secure
8+
const client = twilio(apiKey, apiSecret, { accountSid: myAccountSid });
9+
10+
// Proof request to check credentials are working.
11+
// Retrieving your account information
12+
client.api.accounts.each(accounts => console.log(accounts.sid));

api-auth/api-auth.5.x.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using Twilio;
3+
using Twilio.Rest.Api.V2010;
4+
5+
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your Account Sid from twilio.com/user/account
11+
const string apiKey = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // You can generate this from www.twilio.com/console/runtime/api-keys/create
12+
const string apiSecret = "your_api_secret"; // You can generate this from www.twilio.com/console/runtime/api-keys/create
13+
14+
// DANGER! This is insecure. See http://twil.io/secure
15+
TwilioClient.Init(apiKey, apiSecret, accountSid);
16+
17+
// Proof request to check credentials are working.
18+
// Retrieving your account information
19+
var accounts = AccountResource.Read();
20+
21+
foreach(var record in accounts)
22+
{
23+
Console.WriteLine(record.Sid);
24+
}
25+
}
26+
}

api-auth/api-auth.5.x.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require_once './vendor/autoload.php'; // Loads the library
3+
use Twilio\Rest\Client;
4+
5+
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your Account Sid from twilio.com/user/account
6+
$api_key = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // You can generate this from www.twilio.com/console/runtime/api-keys/create
7+
$api_secret = "your_api_secret"; // You can generate this from www.twilio.com/console/runtime/api-keys/create
8+
9+
// DANGER! This is insecure. See http://twil.io/secure
10+
$client = new Client($api_key, $api_secret, $sid);
11+
12+
// Proof request to check credentials are working.
13+
// Retrieving your account information
14+
$accounts = $client->api->v2010->accounts
15+
->read();
16+
17+
foreach ($accounts as $record) {
18+
print($record->sid);
19+
}
20+
?>

api-auth/api-auth.5.x.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'twilio-ruby'
2+
3+
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Your Account SID from www.twilio.com/console
4+
api_key = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # You can generate this from www.twilio.com/console/runtime/api-keys/create
5+
api_secret = "your_api_secret" # You can generate this from www.twilio.com/console/runtime/api-keys/create
6+
7+
# DANGER! This is insecure. See http://twil.io/secure
8+
@client = Twilio::REST::Client.new api_key, api_secret, account_sid
9+
10+
# Proof request to check credentials are working.
11+
# Retrieving your account information
12+
accounts = @client.api.accounts.list
13+
14+
accounts.each do |record|
15+
puts record.sid
16+
end

api-auth/api-auth.6.x.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from twilio.rest import Client
2+
3+
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Your Account SID from www.twilio.com/console
4+
api_key = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # You can generate this from www.twilio.com/console/runtime/api-keys/create
5+
api_secret = "your_api_secret" # You can generate this from www.twilio.com/console/runtime/api-keys/create
6+
7+
# DANGER! This is insecure. See http://twil.io/secure
8+
client = Client(api_key, api_secret, account_sid)
9+
10+
# Proof request to check credentials are working.
11+
# Retrieving your account information
12+
accounts = client.api.accounts.list()
13+
for record in accounts:
14+
print(record.sid)

api-auth/api-auth.7.x.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import com.twilio.Twilio;
2+
import com.twilio.base.ResourceSet;
3+
import com.twilio.rest.api.v2010.Account;
4+
5+
public class Example {
6+
// Find your Account Sid at twilio.com/user/account
7+
public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
8+
// You can generate these from www.twilio.com/console/runtime/api-keys/create
9+
public static final String API_KEY = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
10+
public static final String API_SECRET = "your_api_secret";
11+
12+
public static void main(String[] args) {
13+
// DANGER! This is insecure. See http://twil.io/secure
14+
Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
15+
16+
// Proof request to check credentials are working.
17+
// Retrieving your account information
18+
ResourceSet<Account> accounts = Account.reader().read();
19+
20+
for(Account record : accounts) {
21+
System.out.println(record.getSid());
22+
}
23+
}
24+
}

api-auth/meta.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"type": "server",
3+
"title": "Authenticate with API Key and API Secret",
4+
"_definition": {
5+
"params": {
6+
"required": {},
7+
"path": {}
8+
},
9+
"location": "https://api.twilio.com/2010-04-01/Accounts.json",
10+
"method": "post",
11+
"domain": "api",
12+
"version": "v2010",
13+
"resource": "account",
14+
"action": "read"
15+
}
16+
}

0 commit comments

Comments
 (0)