Skip to content

Commit

Permalink
Merge pull request #1073 from bprize15/refresh-expired-tokens
Browse files Browse the repository at this point in the history
Enable user to refresh the expired token when there is a valid one
  • Loading branch information
bprize15 authored Jan 9, 2024
2 parents b5bd6e6 + 66de310 commit 715db38
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot-test/__baseline_snapshots__/User Details Page-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void afterPropertiesSet() throws Exception {
}

public List<Token> getUserTokens(User userLogin) {
return tokenService.findValidByUser(userLogin);
return tokenService.findByUser(userLogin);
}

private Token getNewToken(Set<Authority> authorities, Optional<Instant> definedExpirationTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,43 @@ export default class TokenInputGroups extends React.Component<
Expires in {this.getDuration(expirationDay, expirationHour)}
</InputGroup.Text>
</InputGroup.Append>
<DefaultTooltip
placement={'top'}
overlay={
token.renewable
? token.expiration ===
this.sortedTokens[this.sortedTokens.length - 1]
.expiration
? 'Token is up-to-date'
: 'Renew the token'
: 'Token is not renewable'
}
>
<InputGroup.Append>
<Button
variant={'primary'}
onClick={() => {
if (this.props.extendExpirationDate) {
this.props.extendExpirationDate(
token,
this.sortedTokens[this.sortedTokens.length - 1]
.expiration
);
}
}}
disabled={
!this.props.extendExpirationDate ||
!token.renewable ||
token.expiration ===
this.sortedTokens[this.sortedTokens.length - 1]
.expiration
}
style={!token.renewable ? { pointerEvents: 'none' } : {}}
>
<i className={classnames('fa fa-refresh')}></i>
</Button>
</InputGroup.Append>
</DefaultTooltip>
{this.props.changeTokenExpirationDate && (
<CalendarButton
currentDate={token.expiration}
Expand Down
12 changes: 4 additions & 8 deletions src/main/webapp/app/pages/AccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@ export class AccountPage extends React.Component<IRegisterProps> {
});
}

@action
@action.bound
extendExpirationDate(token: Token, newDate: string) {
client
.updateTokenUsingPUT({
token: {
...token,
expiration: newDate,
},
})
this.props.authenticationStore
.extendTokenExpirationDate(token, newDate)
.then(
() => {
notifySuccess('Updated Token');
Expand Down Expand Up @@ -165,6 +160,7 @@ export class AccountPage extends React.Component<IRegisterProps> {
changeTokenExpirationDate={false}
tokens={this.tokens}
onDeleteToken={this.deleteToken}
extendExpirationDate={this.extendExpirationDate}
/>
</InfoRow>
);
Expand Down
25 changes: 25 additions & 0 deletions src/main/webapp/app/store/AuthenticationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ class AuthenticationStore {
});
}

@action
extendTokenExpirationDate(token: Token, newDate: string) {
return new Promise((resolve, reject) => {
client
.updateTokenUsingPUT({
token: {
...token,
expiration: newDate,
},
})
.then((updatedToken: Token) => {
this.getAccountTokens()
.then(() => {
resolve(updatedToken);
})
.catch(error => {
reject(error);
});
})
.catch((error: Error) => {
reject(error);
});
});
}

@computed
get isAuthenticated() {
return !!this.idToken;
Expand Down

0 comments on commit 715db38

Please sign in to comment.