Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: access token theme change #586

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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