Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public class Example {
We are introducing Client Credentials Flow-based OAuth 2.0 authentication.
This feature is currently in `beta` and its implementation is subject to change.

- API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/FetchMessageUsingOAuth.md)
- Organisation API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/BearerTokenAuthentication.md)
- API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/PublicOAuthExample.md)
- Organisation API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/OrgsAPIExample.md)

### Iterate through records

Expand Down
26 changes: 0 additions & 26 deletions examples/BearerTokenAuthentication.md

This file was deleted.

21 changes: 0 additions & 21 deletions examples/FetchMessageUsingOAuth.md

This file was deleted.

34 changes: 34 additions & 0 deletions examples/OrgsAPIExample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class OrgsAPIExample {
public static void main {

private static final String GRANT_TYPE = "grant_type_to_be_used";
private static final String CLIENT_SID =
"client_id_of_the_organization";
private static final String CLIENT_SECRET = "client_secret_of_organization";
private static final String ORGANISATION_ID = "id_of_the_organization";

//Getting access token - Method #1
Twilio.init(new OrgsClientCredentialProvider(CLIENT_SID, CLIENT_SECRET));
fetchAccountDetails();


//Scenario: 2 If in case one doesn't want to change the existing stored credential
// Pass Custom TwilioRestClient
// TokenManager tokenManager = new OrgsTokenManager(GRANT_TYPE, CLIENT_SID, CLIENT_SECRET);
// TokenAuthStrategy tokenAuthStrategy = new TokenAuthStrategy(tokenManager);
// TwilioRestClient client = new TwilioRestClient.Builder(tokenAuthStrategy).build();
// fetchAccountDetailsWithClient(client);
}

private static void fetchAccountDetails() {
ResourceSet<Account> accountSet = Account.reader(ORGANISATION_ID).read();
String accountSid = accountSet.iterator().next().getAccountSid();
System.out.println(accountSid);
}

private static void fetchAccountDetailsWithClient(TwilioRestClient client) {
ResourceSet<Account> accountSet = Account.reader(ORGANISATION_ID).read(client);
String accountSid = accountSet.iterator().next().getAccountSid();
System.out.println(accountSid);
}
}
35 changes: 35 additions & 0 deletions examples/PublicOAuthExample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```
class PublicOAuthExample {
public static void main {

private static final String GRANT_TYPE = "grant_type_to_be_used";
private static final String OAUTH_CLIENT_SID = "client_id";
private static final String OAUTH_CLIENT_SECRET = "client_secret";
private static final String ACCOUNT_SID = "account_sid";
private static final String MESSAGE_SID = "message_sid";

//Getting access token - Method #1
Twilio.init(new ClientCredentialProvider(OAUTH_CLIENT_SID, OAUTH_CLIENT_SECRET), ACCOUNT_SID);
fetchMessage(MESSAGE_SID);


//Scenario: 2 If in case one doesn't want to change the existing stored credential
// Pass Custom TwilioRestClient
// TokenManager tokenManager = new ApiTokenManager(GRANT_TYPE, OAUTH_CLIENT_SID, OAUTH_CLIENT_SECRET);
// TokenAuthStrategy tokenAuthStrategy = new TokenAuthStrategy(tokenManager);
// TwilioRestClient client = new TwilioRestClient.Builder(tokenAuthStrategy).accountSid(ACCOUNT_SID).build();
// fetchMessageWithClient(MESSAGE_SID, client);
}

public static void fetchMessage(String sid) {
Message message = Message.fetcher(sid).fetch();
System.out.println("Fetched Message SID: " + message.getSid());
}

public static void fetchMessageWithClient(String sid, TwilioRestClient client) {
Message message = Message.fetcher(sid).fetch(client);
System.out.println("Fetched Message SID: " + message.getSid());
}
}
```

106 changes: 0 additions & 106 deletions src/main/java/com/twilio/TwilioOrgsTokenAuth.java

This file was deleted.

6 changes: 4 additions & 2 deletions src/main/java/com/twilio/base/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ private static <T> Page<T> buildPage(JsonNode root, List<T> results) {

private static <T> Page<T> buildNextGenPage(JsonNode root, List<T> results) {
JsonNode meta = root.get("meta");
Builder<T> builder = new Builder<T>().url(meta.get("url").asText());

Builder<T> builder = new Builder<>();
if(meta != null && meta.get("url") != null) {
builder = builder.url(meta.get("url").asText());
JsonNode nextPageNode = meta.get("next_page_url");
if (!nextPageNode.isNull()) {
builder.nextPageUrl(nextPageNode.asText());
Expand All @@ -192,6 +193,7 @@ private static <T> Page<T> buildNextGenPage(JsonNode root, List<T> results) {
} else {
builder.pageSize(results.size());
}
}

return builder.records(results).build();
}
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/com/twilio/base/bearertoken/Creator.java

This file was deleted.

51 changes: 0 additions & 51 deletions src/main/java/com/twilio/base/bearertoken/Deleter.java

This file was deleted.

Loading
Loading