Skip to content

Commit

Permalink
#1088 Fix issue that refresh token was lost
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasr authored and ludomikula committed Sep 11, 2024
1 parent 2cd0b06 commit f55fb7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ public Mono<AuthUser> auth(AuthRequestContext authRequestContext) {

public Mono<AuthUser> refresh(String refreshToken) {
return refreshAuthToken(refreshToken)
.flatMap(authToken -> getAuthUser(authToken).doOnNext(authUser -> {
assert authUser.getAuthToken() != null;
authUser.getAuthToken().setAccessToken(authToken.getAccessToken());
authUser.getAuthToken().setExpireIn(authToken.getExpireIn());
}))
.flatMap(authToken -> getAuthUser(authToken).doOnNext(authUser -> authUser.setAuthToken(authToken)))
.onErrorResume(throwable -> {
log.error("failed to refresh token: ", throwable);
return deferredError(FAIL_TO_GET_OIDC_INFO, "FAIL_TO_GET_OIDC_INFO", throwable.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ public void updateConnection(AuthUser authUser, User user) {
// clean old data
oldConnection.setAuthId(authUser.getAuthContext().getAuthConfig().getId());

// Save the auth token which may be used in the future datasource or query.
oldConnection.setAuthConnectionAuthToken(
Optional.ofNullable(authUser.getAuthToken()).map(ConnectionAuthToken::of).orElse(null));
oldConnection.setRawUserInfo(authUser.getRawUserInfo());

//if auth by google, set refresh token
if (authUser.getAuthToken()!=null && oldConnection.getAuthConnectionAuthToken()!=null && StringUtils.isEmpty(authUser.getAuthToken().getRefreshToken()) && StringUtils.isNotEmpty(oldConnection.getAuthConnectionAuthToken().getRefreshToken())) {
authUser.getAuthToken().setRefreshToken(oldConnection.getAuthConnectionAuthToken().getRefreshToken());
}

// Save the auth token which may be used in the future datasource or query.
oldConnection.setAuthConnectionAuthToken(
Optional.ofNullable(authUser.getAuthToken()).map(ConnectionAuthToken::of).orElse(null));
oldConnection.setRawUserInfo(authUser.getRawUserInfo());

user.setActiveAuthId(oldConnection.getAuthId());
}

Expand Down

0 comments on commit f55fb7f

Please sign in to comment.