Skip to content

Commit

Permalink
Fix: MSA account jwt token (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Nov 28, 2022
1 parent f86a0d2 commit 561fc11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/app/views/query-runner/request/auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { authenticationWrapper } from '../../../../../modules/authentication';
import { useAppSelector } from '../../../../../store';

import { componentNames, telemetry } from '../../../../../telemetry';
import { ACCOUNT_TYPE } from '../../../../services/graph-constants';
import { translateMessage } from '../../../../utils/translate-messages';
import { classNames } from '../../../classnames';
import { trackedGenericCopy } from '../../../common/copy';
Expand All @@ -14,7 +15,7 @@ import { convertVhToPx } from '../../../common/dimensions/dimensions-adjustment'
import { authStyles } from './Auth.styles';

export function Auth(props: any) {
const { authToken, dimensions: { request: { height } } } = useAppSelector((state) => state);
const { authToken, profile, dimensions: { request: { height } } } = useAppSelector((state) => state);
const requestHeight = convertVhToPx(height, 60);
const [accessToken, setAccessToken] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -45,17 +46,21 @@ export function Auth(props: any) {
</MessageBar>;
}

const tokenDetailsDisabled = profile?.profileType === ACCOUNT_TYPE.MSA;

return (<div className={classes.auth} style={{ height: requestHeight }}>
{!loading ?
<div>
<div className={classes.accessTokenContainer}>
<Label className={classes.accessTokenLabel}><FormattedMessage id='Access Token' /></Label>
<CopyButton isIconButton={true} handleOnClick={handleCopy} />
<IconButton iconProps={tokenDetailsIcon}
title={translateMessage('Get token details (Powered by jwt.ms)')}
ariaLabel={translateMessage('Get token details (Powered by jwt.ms)')}
title={translateMessage(showMessage())}
ariaLabel={translateMessage(showMessage())}
href={`https://jwt.ms#access_token=${accessToken}`}
target='_blank' />
disabled={tokenDetailsDisabled}
target='_blank'
/>
</div>
<Label className={classes.accessToken} >{accessToken}</Label>
</div>
Expand All @@ -65,6 +70,13 @@ export function Auth(props: any) {
</Label>
}
</div>);

function showMessage(): string {
if (tokenDetailsDisabled) {
return 'This token is not a jwt token and cannot be decoded by jwt.ms'
}
return 'Get token details (Powered by jwt.ms)';
}
}

const trackedComponent = telemetry.trackReactComponent(Auth, componentNames.ACCESS_TOKEN_TAB);
Expand Down
3 changes: 2 additions & 1 deletion src/messages/GE.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,6 @@
"Permission consent type": "Shows whether consent to the permission is personal or tenant-wide",
"Permission propagation delay": "Permission propagation delay",
"Scope consent successful": "Scope consent successful",
"Query documentation": "Query documentation"
"Query documentation": "Query documentation",
"This token is not a jwt token and cannot be decoded by jwt.ms": "This token is not a jwt token and cannot be decoded by jwt.ms"
}

0 comments on commit 561fc11

Please sign in to comment.