Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@
"Shared.AppsAndKeys.ViewCurl.copy.to.clipboard": "Copy to clipboard",
"Shared.AppsAndKeys.ViewCurl.error": "Please generate the Consumer Key and Secret for Residence Key Manager with selecting the urn:ietf:params:oauth:grant-type:token-exchange grant type in order to use the token Exchange Approach.",
"Shared.AppsAndKeys.ViewCurl.help": "The following cURL command shows how to generate an access token using the Password Grant type.",
"Shared.AppsAndKeys.ViewCurl.help.client.credentials": "The following cURL command shows how to generate an access token using the Client Credentials Grant type.",
"Shared.AppsAndKeys.ViewCurl.help.in.a.similar": "In a similar manner, you can generate an access token using the Client Credentials grant type with the following cURL command.",
"Shared.AppsAndKeys.ViewKeys.client.enable.client.credentials": "Enable Client Credentials grant type to generate test access tokens",
"Shared.AppsAndKeys.ViewKeys.consumer.close.btn": "Close",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function ViewCurl(props) {
defaultTokenEndpoint,
consumerSecretMasked,
consumerSecretRequired,
supportedGrantTypes,
} = props;
const bas64Encoded = window.btoa(consumerKey + ':' + consumerSecret);
const [showReal, setShowReal] = useState(false);
Expand Down Expand Up @@ -109,127 +110,145 @@ function ViewCurl(props) {
? `-u "${consumerKey}:<CONSUMER_SECRET>"`
: `-H "Authorization: Basic ${bas64Encoded}"`
};
const showPasswordGrantCurl = !supportedGrantTypes || supportedGrantTypes.includes('password');
const showClientCredentialsGrantCurl = !supportedGrantTypes || supportedGrantTypes.includes('client_credentials');

if (keyManagerConfig.alias === null) {
return (
<Root>
<Typography>
<FormattedMessage
id='Shared.AppsAndKeys.ViewCurl.help'
defaultMessage='The following cURL command shows how to generate an access token using
the Password Grant type.'
/>
</Typography>
{showPasswordGrantCurl && (
<div>
<Typography>
<FormattedMessage
id='Shared.AppsAndKeys.ViewCurl.help'
defaultMessage='The following cURL command shows how to generate an access token using
the Password Grant type.'
/>
</Typography>

<div className={classes.contentWrapper}>
<div className={classes.code} dir='ltr'>
<div>
<span className={classes.command}>curl -k -X POST </span> {tokenEndpoint}
<span className={classes.command}> -d </span>{' '}
{'"grant_type=password&username=Username&password=Password"'}
</div>
{isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : (
<div className={classes.contentWrapper}>
<div className={classes.code} dir='ltr'>
<div>
<span className={classes.command}>curl -k -X POST </span> {tokenEndpoint}
<span className={classes.command}> -d </span>{' '}
{'"grant_type=password&username=Username&password=Password"'}
</div>
{isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : (
<div>
<span className={classes.command}> -H </span>
{'"Authorization: Basic'}
<a onClick={applyReal} className={classes.encodeVisible}>
{showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'}
</a>
{'"'}
</div>
)}
</div>
<div>
<span className={classes.command}> -H </span>
{'"Authorization: Basic'}
<a onClick={applyReal} className={classes.encodeVisible}>
{showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'}
</a>
{'"'}
<Tooltip
title={
tokenCopied
? intl.formatMessage({
defaultMessage: 'Copied',
id: 'Shared.AppsAndKeys.ViewCurl.copied',
})
: intl.formatMessage({
defaultMessage: 'Copy to clipboard',
id: 'Shared.AppsAndKeys.ViewCurl.copy.to.clipboard',
})
}
placement='right'
>
<IconButton
id = 'copy-to-clipbord-icon'
aria-label='Copy to clipboard'
size="large"
onClick={() => {
navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` +
'"grant_type=password&username=Username&password=Password" ' +
`${getAuthSnippetString()}`).then(onCopy)
}}
>
<FileCopy color='secondary'/>
</IconButton>
</Tooltip>
</div>
)}
</div>
</div>
)}
{showClientCredentialsGrantCurl && (
<div>
<Tooltip
title={
tokenCopied
? intl.formatMessage({
defaultMessage: 'Copied',
id: 'Shared.AppsAndKeys.ViewCurl.copied',
})
: intl.formatMessage({
defaultMessage: 'Copy to clipboard',
id: 'Shared.AppsAndKeys.ViewCurl.copy.to.clipboard',
})
}
placement='right'
>
<IconButton
id = 'copy-to-clipbord-icon'
aria-label='Copy to clipboard'
size="large"
onClick={() => {
navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` +
'"grant_type=password&username=Username&password=Password" ' +
`${getAuthSnippetString()}`).then(onCopy)
}}
>
<FileCopy color='secondary'/>
</IconButton>
</Tooltip>
</div>
</div>
<Typography>
<FormattedMessage
id='Shared.AppsAndKeys.ViewCurl.help.in.a.similar'
defaultMessage={`In a similar manner, you can generate an access token using the
Client Credentials grant type with the following cURL command.`}
/>
</Typography>
<div className={classes.contentWrapper}>
<div className={classes.code} dir='ltr'>
<div>
<span className={classes.command}>curl -k -X POST </span> {tokenEndpoint}
<span className={classes.command}> -d </span>{' '}
{'"grant_type=client_credentials"'}
{isAzureAD && (
<>
<span className={classes.command}> -d </span>
{' '}
{`"scope=api://${consumerKey}/.default"`}
</>
<Typography>
{showPasswordGrantCurl ? (
<FormattedMessage
id='Shared.AppsAndKeys.ViewCurl.help.in.a.similar'
defaultMessage={`In a similar manner, you can generate an access token using the
Client Credentials grant type with the following cURL command.`}
/>
) : (
<FormattedMessage
id='Shared.AppsAndKeys.ViewCurl.help.client.credentials'
defaultMessage='The following cURL command shows how to generate an access token using the Client Credentials Grant type.'
/>
)}
</div>
{isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : (
</Typography>

<div className={classes.contentWrapper}>
<div className={classes.code} dir='ltr'>
<div>
<span className={classes.command}>curl -k -X POST </span> {tokenEndpoint}
<span className={classes.command}> -d </span>{' '}
{'"grant_type=client_credentials"'}
{isAzureAD && (
<>
<span className={classes.command}> -d </span>
{' '}
{`"scope=api://${consumerKey}/.default"`}
</>
)}
</div>
{isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : (
<div>
<span className={classes.command}> -H </span>
{'"Authorization: Basic'}
<a onClick={applyReal} className={classes.encodeVisible}>
{showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'}
</a>
{'"'}
</div>
)}
</div>
<div>
<span className={classes.command}> -H </span>
{'"Authorization: Basic'}
<a onClick={applyReal} className={classes.encodeVisible}>
{showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'}
</a>
{'"'}
<Tooltip
title={
tokenCopied
? intl.formatMessage({
defaultMessage: 'Copied',
id: 'Shared.AppsAndKeys.ViewCurl.copied',
})
: intl.formatMessage({
defaultMessage: 'Copy to clipboard',
id: 'Shared.AppsAndKeys.ViewCurl.copy.to.clipboard',
})
}
placement='right'
>
<IconButton
id = 'copy-to-clipbord-icon'
aria-label='Copy to clipboard'
size="large"
onClick={() => {navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` +
'"grant_type=client_credentials"' + azureScope + ' ' +
`${getAuthSnippetString()}`).then(onCopy)
}}
>
<FileCopy color='secondary'/>
</IconButton>
</Tooltip>
</div>
)}
</div>
<div>
<Tooltip
title={
tokenCopied
? intl.formatMessage({
defaultMessage: 'Copied',
id: 'Shared.AppsAndKeys.ViewCurl.copied',
})
: intl.formatMessage({
defaultMessage: 'Copy to clipboard',
id: 'Shared.AppsAndKeys.ViewCurl.copy.to.clipboard',
})
}
placement='right'
>
<IconButton
id = 'copy-to-clipbord-icon'
aria-label='Copy to clipboard'
size="large"
onClick={() => {navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` +
'"grant_type=client_credentials"' + azureScope + ' ' +
`${getAuthSnippetString()}`).then(onCopy)
}}
>
<FileCopy color='secondary'/>
</IconButton>
</Tooltip>
</div>
</div>
</div>
)}
</Root>
);
} else {
Expand Down Expand Up @@ -328,6 +347,7 @@ ViewCurl.propTypes = {
defaultTokenEndpoint: PropTypes.string,
consumerSecretMasked: PropTypes.bool,
consumerSecretRequired: PropTypes.bool,
supportedGrantTypes: PropTypes.array,
};

export default injectIntl(ViewCurl);
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class ViewKeys extends React.Component {
}

// Get the grant types for the generated keys
const { supportedGrantTypes: supportedGrantTypesUnchanged } = keys.get(selectedTab);
const { supportedGrantTypes: supportedGrantTypesUnchanged = [] } = keys.get(selectedTab);
return consumerKey && (
<Root className={classes.inputWrapper}>
<Grid container spacing={3}>
Expand Down Expand Up @@ -663,6 +663,7 @@ class ViewKeys extends React.Component {
keyType={keyType}
keyManagerConfig={keyManagerConfig}
consumerSecretMasked={consumerSecretRequired}
supportedGrantTypes={supportedGrantTypesUnchanged}
/>
</DialogContentText>
)}
Expand Down Expand Up @@ -740,19 +741,24 @@ class ViewKeys extends React.Component {
/>
</Button>
)}
<Button
id='curl-to-generate-access-token-btn'
variant='outlined'
size='small'
color='grey'
className={classes.margin}
onClick={this.handleClickOpenCurl}
>
<FormattedMessage
id='Shared.AppsAndKeys.ViewKeys.curl.to.generate'
defaultMessage='CURL to Generate Access Token'
/>
</Button>
{supportedGrantTypesUnchanged
&& (supportedGrantTypesUnchanged.includes('password')
|| supportedGrantTypesUnchanged.includes('client_credentials'))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
&& (
<Button
id='curl-to-generate-access-token-btn'
variant='outlined'
size='small'
color='grey'
className={classes.margin}
onClick={this.handleClickOpenCurl}
>
<FormattedMessage
id='Shared.AppsAndKeys.ViewKeys.curl.to.generate'
defaultMessage='CURL to Generate Access Token'
/>
</Button>
)}
</div>
</>
{supportedGrantTypesUnchanged && !supportedGrantTypesUnchanged.includes('client_credentials') && (
Expand Down
Loading