Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class ApiTokenManager implements TokenManager {

@Override
public String fetchAccessToken() {
TokenCreator tokenCreator = Token.creator().setGrantType(grantType).setClientId(clientId).setClientSecret(clientSecret);
TokenCreator tokenCreator = Token.creator(grantType).setClientId(clientId).setClientSecret(clientSecret);

if (this.code != null) tokenCreator.setCode(code);
if (this.redirectUri != null) tokenCreator.setRedirectUri(redirectUri);
if (this.audience != null) tokenCreator.setAudience(audience);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public OrgsTokenManager(String grantType, String clientId, String clientSecret,
}

public synchronized String fetchAccessToken(){
TokenCreator tokenCreator = Token.creator().setGrantType(grantType).setClientId(clientId).setClientSecret(clientSecret);
TokenCreator tokenCreator = Token.creator(grantType).setClientId(clientId).setClientSecret(clientSecret);
if (this.code != null) tokenCreator.setCode(code);
if (this.redirectUri != null) tokenCreator.setRedirectUri(redirectUri);
if (this.audience != null) tokenCreator.setAudience(audience);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/twilio/rest/oauth/v2/Authorize.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.base.Resource;
import com.twilio.base.Resource;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
import com.twilio.type.*;
Expand All @@ -43,6 +45,26 @@ public static AuthorizeFetcher fetcher() {
return new AuthorizeFetcher();
}

public enum CodeChallengeMethod {
S256("S256");

private final String value;

private CodeChallengeMethod(final String value) {
this.value = value;
}

@JsonValue
public String toString() {
return value;
}

@JsonCreator
public static CodeChallengeMethod forValue(final String value) {
return Promoter.enumFromString(value, CodeChallengeMethod.values());
}
}

/**
* Converts a JSON String into a Authorize object using the provided ObjectMapper.
*
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/twilio/rest/oauth/v2/AuthorizeFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class AuthorizeFetcher extends Fetcher<Authorize> {
private String redirectUri;
private String scope;
private String state;
private String codeChallenge;
private Authorize.CodeChallengeMethod codeChallengeMethod;

public AuthorizeFetcher() {}

Expand Down Expand Up @@ -65,6 +67,18 @@ public AuthorizeFetcher setState(final String state) {
return this;
}

public AuthorizeFetcher setCodeChallenge(final String codeChallenge) {
this.codeChallenge = codeChallenge;
return this;
}

public AuthorizeFetcher setCodeChallengeMethod(
final Authorize.CodeChallengeMethod codeChallengeMethod
) {
this.codeChallengeMethod = codeChallengeMethod;
return this;
}

private Response makeRequest(final TwilioRestClient client) {
String path = "/v2/authorize";

Expand Down Expand Up @@ -159,5 +173,23 @@ private void addQueryParams(final Request request) {
if (state != null) {
Serializer.toString(request, "state", state, ParameterType.QUERY);
}

if (codeChallenge != null) {
Serializer.toString(
request,
"code_challenge",
codeChallenge,
ParameterType.QUERY
);
}

if (codeChallengeMethod != null) {
Serializer.toString(
request,
"code_challenge_method",
codeChallengeMethod,
ParameterType.QUERY
);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/twilio/rest/oauth/v2/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
@ToString
public class Token extends Resource {

public static TokenCreator creator() {
return new TokenCreator();
public static TokenCreator creator(final String grantType) {
return new TokenCreator(grantType);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/twilio/rest/oauth/v2/TokenCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ public class TokenCreator extends Creator<Token> {
private String audience;
private String refreshToken;
private String scope;
private String codeVerifier;

public TokenCreator() {}
public TokenCreator(final String grantType) {
this.grantType = grantType;
}

public TokenCreator setGrantType(final String grantType) {
this.grantType = grantType;
Expand Down Expand Up @@ -85,6 +88,11 @@ public TokenCreator setScope(final String scope) {
return this;
}

public TokenCreator setCodeVerifier(final String codeVerifier) {
this.codeVerifier = codeVerifier;
return this;
}

public TokenCreator setAccountSid(final String accountSid) {
this.accountSid = accountSid;
return this;
Expand Down Expand Up @@ -231,5 +239,14 @@ private void addPostParams(final Request request) {
ParameterType.URLENCODED
);
}

if (codeVerifier != null) {
Serializer.toString(
request,
"code_verifier",
codeVerifier,
ParameterType.URLENCODED
);
}
}
}