Skip to content

Commit

Permalink
Fix: access token theme change (#586)
Browse files Browse the repository at this point in the history
* change access token theme

* refresh tokens every 10 minutes to get the latest one
  • Loading branch information
thewahome committed Jun 23, 2020
1 parent a324abd commit 413465e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/app/views/query-runner/request/auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import React from 'react';
import { FormattedMessage } from 'react-intl';
import { useSelector } from 'react-redux';
import { classNames } from '../../../classnames';
import { copy } from '../../../common/copy';
import { genericCopy } from '../../../common/copy';
import { authStyles } from './Auth.styles';

async function handleCopy() {
await copy('access-token');
}

export function Auth(props: any) {
const accessToken = useSelector((state: any) => state.authToken);

const handleCopy = async () => {
await genericCopy(accessToken);
};

const classes = classNames(props);
const copyIcon: IIconProps = {
iconName: 'copy'
Expand All @@ -25,7 +26,7 @@ export function Auth(props: any) {
<Label className={classes.accessTokenLabel}><FormattedMessage id='Access Token' /></Label>
<IconButton onClick={handleCopy} iconProps={copyIcon} title='Copy' ariaLabel='Copy' />
</div>
<textarea className={classes.accessToken} id='access-token' value={accessToken} readOnly={true} />
<Label className={classes.accessToken} >{accessToken}</Label>
</div>
:
<Label className={classes.emptyStateLabel}>
Expand Down
21 changes: 13 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,19 @@ const appState: any = store({

});

msalApplication.acquireTokenSilent({ scopes: DEFAULT_USER_SCOPES.split(' ') }).then((authResponse: any) => {
if (authResponse && authResponse.accessToken) {
appState.dispatch(getAuthTokenSuccess(authResponse.accessToken));
appState.dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
}).catch(() => {
// ignore the error as it means that a User login is required
});
function refreshAccessToken() {
msalApplication.acquireTokenSilent({ scopes: DEFAULT_USER_SCOPES.split(' ') }).then((authResponse: any) => {
if (authResponse && authResponse.accessToken) {
appState.dispatch(getAuthTokenSuccess(authResponse.accessToken));
appState.dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
}).catch(() => {
// ignore the error as it means that a User login is required
});
}
refreshAccessToken();

setInterval(refreshAccessToken, 1000 * 60 * 10); // refresh access token every 10 minutes

addLocaleData([
...pt,
Expand Down

0 comments on commit 413465e

Please sign in to comment.