Skip to content

Commit 47f0be6

Browse files
committed
Modify OAuth20ProfileCreator to add refresh token to profile
1 parent 8088519 commit 47f0be6

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/main/java/org/pac4j/oauth/profile/creator/OAuth20ProfileCreator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.github.scribejava.core.model.*;
44
import com.github.scribejava.core.oauth.OAuth20Service;
5+
6+
import org.apache.commons.lang3.StringUtils;
7+
58
import org.pac4j.core.client.IndirectClient;
69
import org.pac4j.core.context.HttpConstants;
710
import org.pac4j.oauth.config.OAuth20Configuration;
@@ -12,12 +15,18 @@
1215
/**
1316
* OAuth 2.0 profile creator.
1417
*
18+
* OSF CAS Customization: modified {@code addAccessTokenToProfile} to include refresh token in profile attributes.
19+
*
1520
* @author Jerome Leleu
21+
* @author Longze Chen
1622
* @since 2.0.0
23+
* @version 4.1.0
1724
*/
1825
public class OAuth20ProfileCreator<U extends OAuth20Profile>
1926
extends OAuthProfileCreator<OAuth20Credentials, U, OAuth20Configuration, OAuth2AccessToken, OAuth20Service> {
2027

28+
private static final String REFRESH_TOKEN = "refresh_token";
29+
2130
public OAuth20ProfileCreator(final OAuth20Configuration configuration, final IndirectClient client) {
2231
super(configuration, client);
2332
}
@@ -33,6 +42,11 @@ protected void addAccessTokenToProfile(final U profile, final OAuth2AccessToken
3342
final String token = accessToken.getAccessToken();
3443
logger.debug("add access_token: {} to profile", token);
3544
profile.setAccessToken(token);
45+
final String refreshToken = accessToken.getRefreshToken();
46+
if (StringUtils.isNoneBlank(refreshToken)) {
47+
logger.debug("add refresh_token: {} to profile", token);
48+
profile.addAttribute(REFRESH_TOKEN, refreshToken);
49+
}
3650
}
3751
}
3852

0 commit comments

Comments
 (0)