1313public class AuthClient {
1414 private final ApiClient apiClient ;
1515 private final Consumer <String > onAuthenticate ;
16+ private String currentAccessToken ;
1617
1718 public AuthClient (ApiClient apiClient , Consumer <String > onAuthenticate ) {
1819 this .apiClient = apiClient ;
1920 this .onAuthenticate = onAuthenticate ;
2021 }
2122
23+ public AuthClient (ApiClient apiClient , Consumer <String > onAuthenticate , String initialToken ) {
24+ this .apiClient = apiClient ;
25+ this .onAuthenticate = onAuthenticate ;
26+ this .currentAccessToken = initialToken ;
27+ }
28+
2229 public void UniversalAuthLogin (String clientId , String clientSecret ) throws InfisicalException {
2330 UniversalAuthLoginInput params = UniversalAuthLoginInput .builder ().clientId (clientId ).clientSecret (clientSecret )
2431 .build ();
2532
2633 String url = String .format ("%s%s" , this .apiClient .GetBaseUrl (), "/api/v1/auth/universal-auth/login" );
2734 MachineIdentityCredential credential = this .apiClient .post (url , params , MachineIdentityCredential .class );
28- this .onAuthenticate .accept (credential .getAccessToken ());
35+ this .currentAccessToken = credential .getAccessToken ();
36+ this .onAuthenticate .accept (this .currentAccessToken );
2937 }
3038
3139 public void LdapAuthLogin (LdapAuthLoginInput input ) throws InfisicalException {
@@ -37,7 +45,8 @@ public void LdapAuthLogin(LdapAuthLoginInput input) throws InfisicalException {
3745
3846 String url = String .format ("%s%s" , this .apiClient .GetBaseUrl (), "/api/v1/auth/ldap-auth/login" );
3947 MachineIdentityCredential credential = this .apiClient .post (url , input , MachineIdentityCredential .class );
40- this .onAuthenticate .accept (credential .getAccessToken ());
48+ this .currentAccessToken = credential .getAccessToken ();
49+ this .onAuthenticate .accept (this .currentAccessToken );
4150 }
4251
4352 public void AwsAuthLogin (String identityId ) throws InfisicalException {
@@ -53,13 +62,19 @@ public void AwsAuthLogin(AwsAuthLoginInput input) throws InfisicalException {
5362
5463 String url = String .format ("%s%s" , this .apiClient .GetBaseUrl (), "/api/v1/auth/aws-auth/login" );
5564 MachineIdentityCredential credential = this .apiClient .post (url , input , MachineIdentityCredential .class );
56- this .onAuthenticate .accept (credential .getAccessToken ());
65+ this .currentAccessToken = credential .getAccessToken ();
66+ this .onAuthenticate .accept (this .currentAccessToken );
5767 }
5868
5969 public void SetAccessToken (String accessToken ) {
70+ this .currentAccessToken = accessToken ;
6071 this .onAuthenticate .accept (accessToken );
6172 }
6273
74+ public void RevokeToken () throws InfisicalException {
75+ RevokeToken (this .currentAccessToken );
76+ }
77+
6378 public void RevokeToken (String accessToken ) throws InfisicalException {
6479 RevokeTokenInput input = RevokeTokenInput .builder ().accessToken (accessToken ).build ();
6580
0 commit comments