Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 6f9a7bf

Browse files
authored
Merge pull request #898 from TwilioDevEd/DI-1287
update snippets for twilio-java 8.x
2 parents 5283480 + c0d2e77 commit 6f9a7bf

File tree

518 files changed

+189
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

518 files changed

+189
-2
lines changed

add-ons/lookups/payfone-tcpa-compliance/payfone-tcpa-compliance.7.x.java renamed to add-ons/lookups/payfone-tcpa-compliance/payfone-tcpa-compliance.8.x.java

File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.io.IOException;
2+
import java.util.List;
3+
import java.util.Arrays;
4+
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
9+
import com.twilio.jwt.client.ClientCapability;
10+
import com.twilio.jwt.client.IncomingClientScope;
11+
import com.twilio.jwt.client.OutgoingClientScope;
12+
import com.twilio.jwt.client.Scope;
13+
14+
public class TwilioServlet extends HttpServlet {
15+
16+
// Get your Account SID and Auth Token from https://twilio.com/console
17+
// To set up environment variables, see http://twil.io/secure
18+
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
19+
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
20+
// Find an application Sid from twilio.com/user/account/apps
21+
public static final String APP_SID = System.getenv("TWILIO_APP_SID");
22+
23+
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
24+
OutgoingClientScope outgoingScope = new OutgoingClientScope.Builder(APP_SID).build();
25+
IncomingClientScope incomingScope = new IncomingClientScope(request.getParameter("ClientName"));
26+
27+
List<Scope> scopes = Arrays.asList(outgoingScope, incomingScope);
28+
29+
ClientCapability capability = new ClientCapability.Builder(ACCOUNT_SID, AUTH_TOKEN)
30+
.scopes(scopes)
31+
.build();
32+
33+
String token = capability.toJwt();
34+
35+
response.setContentType("application/jwt");
36+
response.getWriter().print(token);
37+
}
38+
}

client/capability-token-expires/capability-token-expires.7.x.java renamed to client/capability-token-expires/capability-token-expires.8.x.java

File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.IOException;
2+
import java.util.List;
3+
import java.util.Arrays;
4+
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
9+
import com.twilio.jwt.client.ClientCapability;
10+
import com.twilio.jwt.client.IncomingClientScope;
11+
import com.twilio.jwt.client.Scope;
12+
13+
public class TwilioServlet extends HttpServlet {
14+
15+
// Get your Account SID and Auth Token from https://twilio.com/console
16+
// To set up environment variables, see http://twil.io/secure
17+
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
18+
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
19+
20+
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
21+
List<Scope> scopes = Arrays.asList(new IncomingClientScope("joey"));
22+
23+
ClientCapability capability = new ClientCapability.Builder(ACCOUNT_SID, AUTH_TOKEN)
24+
.scopes(scopes)
25+
.build();
26+
27+
String token = capability.toJwt();
28+
29+
response.setContentType("application/jwt");
30+
response.getWriter().print(token);
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.IOException;
2+
import java.util.List;
3+
import java.util.Arrays;
4+
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
9+
import com.twilio.jwt.client.ClientCapability;
10+
import com.twilio.jwt.client.OutgoingClientScope;
11+
import com.twilio.jwt.client.Scope;
12+
13+
public class TwilioServlet extends HttpServlet {
14+
15+
// Get your Account SID and Auth Token from https://twilio.com/console
16+
// To set up environment variables, see http://twil.io/secure
17+
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
18+
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
19+
// Find an application Sid from twilio.com/user/account/apps
20+
public static final String APP_SID = System.getenv("TWILIO_APP_SID");]
21+
22+
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
23+
List<Scope> scopes =
24+
Arrays.asList(new OutgoingClientScope.Builder(APP_SID).build());
25+
26+
ClientCapability capability =
27+
new ClientCapability.Builder(ACCOUNT_SID, AUTH_TOKEN).scopes(scopes).build();
28+
29+
String token = capability.toJwt();
30+
31+
response.setContentType("application/jwt");
32+
response.getWriter().print(token);
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.io.IOException;
2+
import java.util.List;
3+
import java.util.Arrays;
4+
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
9+
import com.twilio.jwt.client.ClientCapability;
10+
import com.twilio.jwt.client.IncomingClientScope;
11+
import com.twilio.jwt.client.OutgoingClientScope;
12+
import com.twilio.jwt.client.Scope;
13+
14+
public class TwilioServlet extends HttpServlet {
15+
16+
// Get your Account SID and Auth Token from https://twilio.com/console
17+
// To set up environment variables, see http://twil.io/secure
18+
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
19+
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
20+
// Find an application Sid from twilio.com/user/account/apps
21+
public static final String APP_SID = System.getenv("TWILIO_APP_SID");
22+
23+
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
24+
OutgoingClientScope outgoingScope = new OutgoingClientScope.Builder(APP_SID).build();
25+
IncomingClientScope incomingScope = new IncomingClientScope("joey");
26+
27+
List<Scope> scopes = Arrays.asList(outgoingScope, incomingScope);
28+
29+
ClientCapability capability = new ClientCapability.Builder(ACCOUNT_SID, AUTH_TOKEN)
30+
.scopes(scopes)
31+
.build();
32+
33+
String token = capability.toJwt();
34+
35+
response.setContentType("application/jwt");
36+
response.getWriter().print(token);
37+
}
38+
}

client/response-twiml-client/response-twiml-client.7.x.java renamed to client/response-twiml-client/response-twiml-client.8.x.java

File renamed without changes.

client/response-twiml-dial/response-twiml-dial.7.x.java renamed to client/response-twiml-dial/response-twiml-dial.8.x.java

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)