diff --git a/portals/devportal/src/main/webapp/site/public/locales/en.json b/portals/devportal/src/main/webapp/site/public/locales/en.json index 7a88d84e4f7..de31438f3f1 100644 --- a/portals/devportal/src/main/webapp/site/public/locales/en.json +++ b/portals/devportal/src/main/webapp/site/public/locales/en.json @@ -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", diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewCurl.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewCurl.jsx index bbfc283561b..605954942f9 100755 --- a/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewCurl.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewCurl.jsx @@ -76,6 +76,7 @@ function ViewCurl(props) { defaultTokenEndpoint, consumerSecretMasked, consumerSecretRequired, + supportedGrantTypes, } = props; const bas64Encoded = window.btoa(consumerKey + ':' + consumerSecret); const [showReal, setShowReal] = useState(false); @@ -109,127 +110,145 @@ function ViewCurl(props) { ? `-u "${consumerKey}:"` : `-H "Authorization: Basic ${bas64Encoded}"` }; + const showPasswordGrantCurl = !supportedGrantTypes || supportedGrantTypes.includes('password'); + const showClientCredentialsGrantCurl = !supportedGrantTypes || supportedGrantTypes.includes('client_credentials'); if (keyManagerConfig.alias === null) { return ( - - - + {showPasswordGrantCurl && ( +
+ + + -
-
-
- curl -k -X POST {tokenEndpoint} - -d {' '} - {'"grant_type=password&username=Username&password=Password"'} -
- {isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : ( +
+
+
+ curl -k -X POST {tokenEndpoint} + -d {' '} + {'"grant_type=password&username=Username&password=Password"'} +
+ {isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : ( + + )} +
- -H - {'"Authorization: Basic'} - - {showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'} - - {'"'} + + { + navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` + + '"grant_type=password&username=Username&password=Password" ' + + `${getAuthSnippetString()}`).then(onCopy) + }} + > + + +
- )} +
+ )} + {showClientCredentialsGrantCurl && (
- - { - navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` + - '"grant_type=password&username=Username&password=Password" ' + - `${getAuthSnippetString()}`).then(onCopy) - }} - > - - - -
-
- - - -
-
-
- curl -k -X POST {tokenEndpoint} - -d {' '} - {'"grant_type=client_credentials"'} - {isAzureAD && ( - <> - -d - {' '} - {`"scope=api://${consumerKey}/.default"`} - + + {showPasswordGrantCurl ? ( + + ) : ( + )} -
- {isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : ( + + +
+
+
+ curl -k -X POST {tokenEndpoint} + -d {' '} + {'"grant_type=client_credentials"'} + {isAzureAD && ( + <> + -d + {' '} + {`"scope=api://${consumerKey}/.default"`} + + )} +
+ {isConsumerSecretRequired ? (consumerSecretRequiredSnippet) : ( + + )} +
- -H - {'"Authorization: Basic'} - - {showReal ? ' ' + bas64Encoded : ' Base64(consumer-key:consumer-secret)'} - - {'"'} + + {navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` + + '"grant_type=client_credentials"' + azureScope + ' ' + + `${getAuthSnippetString()}`).then(onCopy) + }} + > + + +
- )} -
-
- - {navigator.clipboard.writeText(`curl -k -X POST ${tokenEndpoint} -d ` + - '"grant_type=client_credentials"' + azureScope + ' ' + - `${getAuthSnippetString()}`).then(onCopy) - }} - > - - - +
-
+ )} ); } else { @@ -328,6 +347,7 @@ ViewCurl.propTypes = { defaultTokenEndpoint: PropTypes.string, consumerSecretMasked: PropTypes.bool, consumerSecretRequired: PropTypes.bool, + supportedGrantTypes: PropTypes.array, }; export default injectIntl(ViewCurl); diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewKeys.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewKeys.jsx index 97a4b5ef83b..6fee84a64be 100755 --- a/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewKeys.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Shared/AppsAndKeys/ViewKeys.jsx @@ -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 && ( @@ -663,6 +663,7 @@ class ViewKeys extends React.Component { keyType={keyType} keyManagerConfig={keyManagerConfig} consumerSecretMasked={consumerSecretRequired} + supportedGrantTypes={supportedGrantTypesUnchanged} /> )} @@ -740,19 +741,24 @@ class ViewKeys extends React.Component { /> )} - + {supportedGrantTypesUnchanged + && (supportedGrantTypesUnchanged.includes('password') + || supportedGrantTypesUnchanged.includes('client_credentials')) + && ( + + )}
{supportedGrantTypesUnchanged && !supportedGrantTypesUnchanged.includes('client_credentials') && (