Skip to content

Commit 75a6b1e

Browse files
committed
feat: Implement token storage via TokenCallback interface
- Add TokenCallback interface for token storage events - Update OAuthConfig to include tokenCallback - Update OAuthHandler to use callback for token events
1 parent 96403b1 commit 75a6b1e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/main/java/com/contentstack/cms/models/OAuthConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010

1111
import com.contentstack.cms.core.Util;
12+
import com.contentstack.cms.oauth.TokenCallback;
1213

1314
/**
1415
* Configuration class for OAuth 2.0 authentication
@@ -27,6 +28,11 @@ public class OAuthConfig {
2728
private final String tokenEndpoint;
2829
private final String host;
2930

31+
/**
32+
* Callback for token events
33+
*/
34+
private final TokenCallback tokenCallback;
35+
3036
/**
3137
* Validates the configuration
3238
*

src/main/java/com/contentstack/cms/oauth/OAuthHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ public CompletableFuture<OAuthTokens> exchangeCodeForToken(String code) {
193193
private void _saveTokens(OAuthTokens tokens) {
194194
synchronized (tokenLock) {
195195
this.tokens = tokens;
196+
if (config.getTokenCallback() != null) {
197+
if (tokens != null) {
198+
config.getTokenCallback().onTokensUpdated(tokens);
199+
} else {
200+
config.getTokenCallback().onTokensCleared();
201+
}
202+
}
196203
}
197204
}
198205

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.contentstack.cms.oauth;
2+
3+
import com.contentstack.cms.models.OAuthTokens;
4+
5+
/**
6+
* Callback interface for token events
7+
*/
8+
public interface TokenCallback {
9+
/**
10+
* Called when tokens are updated
11+
* @param tokens The new tokens
12+
*/
13+
void onTokensUpdated(OAuthTokens tokens);
14+
15+
/**
16+
* Called when tokens are cleared
17+
*/
18+
void onTokensCleared();
19+
}

0 commit comments

Comments
 (0)