From f88861cba51c9e3624b44ba0a4625dac7c17b5ff Mon Sep 17 00:00:00 2001 From: akila94 Date: Fri, 8 Nov 2024 20:35:02 +0530 Subject: [PATCH] Fix refresh token validity period issue --- .../CDSAuthorizationCodeGrantHandler.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/org.wso2.openbanking.cds.identity/src/main/java/org/wso2/openbanking/cds/identity/grant/type/handlers/CDSAuthorizationCodeGrantHandler.java b/components/org.wso2.openbanking.cds.identity/src/main/java/org/wso2/openbanking/cds/identity/grant/type/handlers/CDSAuthorizationCodeGrantHandler.java index a73920b2..ea9f387e 100644 --- a/components/org.wso2.openbanking.cds.identity/src/main/java/org/wso2/openbanking/cds/identity/grant/type/handlers/CDSAuthorizationCodeGrantHandler.java +++ b/components/org.wso2.openbanking.cds.identity/src/main/java/org/wso2/openbanking/cds/identity/grant/type/handlers/CDSAuthorizationCodeGrantHandler.java @@ -110,7 +110,7 @@ public void publishUserAccessTokenData(OAuth2AccessTokenRespDTO oAuth2AccessToke * @return */ @Override - public boolean issueRefreshToken() throws IdentityOAuth2Exception { + public OAuth2AccessTokenRespDTO issue(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { OAuthTokenReqMessageContext tokenReqMessageContext = getTokenMessageContext(); @@ -124,10 +124,21 @@ public boolean issueRefreshToken() throws IdentityOAuth2Exception { if (log.isDebugEnabled()) { log.debug("Refresh token validity period is set to: " + sharingDuration); } - // do not issue refresh token if sharing duration value equals to zero - if (sharingDuration == 0) { - return false; - } + + } + return super.issue(tokReqMsgCtx); + } + + @Override + public boolean issueRefreshToken() throws IdentityOAuth2Exception { + + OAuthTokenReqMessageContext tokenReqMessageContext = getTokenMessageContext(); + if (isRegulatory(tokenReqMessageContext)) { + long sharingDuration; + String[] scopes = tokenReqMessageContext.getScope(); + String consentId = CDSIdentityUtil.getConsentId(scopes); + sharingDuration = CDSIdentityUtil.getRefreshTokenValidityPeriod(consentId); + return sharingDuration != 0; } return true; }