-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
98 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/twilio/http/bearertoken/OrgsTokenManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.twilio.http.bearertoken; | ||
|
||
import lombok.Setter; | ||
import com.twilio.exception.ApiException; | ||
import lombok.RequiredArgsConstructor; | ||
import com.twilio.rest.previewiam.organizations.Token; | ||
import com.twilio.rest.previewiam.organizations.TokenCreator; | ||
public class OrgsTokenManager implements TokenManager{ | ||
|
||
private final String grantType; | ||
private final String clientId; | ||
private final String clientSecret; | ||
private String code; | ||
private String redirectUri; | ||
private String audience; | ||
private String refreshToken; | ||
private String scope; | ||
|
||
public OrgsTokenManager(String grantType, String clientId, String clientSecret){ | ||
this.grantType = grantType; | ||
this.clientId = clientId; | ||
this.clientSecret = clientSecret; | ||
} | ||
|
||
public OrgsTokenManager(String grantType, String clientId, String clientSecret, String code, String redirectUri, String audience, String refreshToken, String scope){ | ||
this.grantType = grantType; | ||
this.clientId = clientId; | ||
this.clientSecret = clientSecret; | ||
this.code = code; | ||
this.redirectUri = redirectUri; | ||
this.audience = audience; | ||
this.refreshToken = refreshToken; | ||
this.scope = scope; | ||
} | ||
|
||
public synchronized String fetchAccessToken(){ | ||
TokenCreator tokenCreator = Token.creator(grantType, clientId).setClientSecret(clientSecret); | ||
if (this.code != null) tokenCreator.setCode(code); | ||
if (this.redirectUri != null) tokenCreator.setRedirectUri(redirectUri); | ||
if (this.audience != null) tokenCreator.setAudience(audience); | ||
if (this.refreshToken != null) tokenCreator.setRefreshToken(refreshToken); | ||
if (this.scope != null) tokenCreator.setScope(scope); | ||
Token token; | ||
try { | ||
token = tokenCreator.create(); | ||
} catch(Exception e){ | ||
throw new ApiException("Token creation failed"); | ||
} | ||
return token.getAccessToken(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package com.twilio.http.bearertoken; | ||
|
||
public interface TokenManager { | ||
public String refreshAccessToken(String refreshToken); | ||
public String fetchAccessToken(); | ||
} |
25 changes: 0 additions & 25 deletions
25
src/main/java/com/twilio/http/bearertoken/TokenManagerImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters