B2C Service - How to use cURL to access the Connect REST API with IDCS OAuth Token

Hi,

In this post, I will discuss how to use cURL to validate IDCS access token. It will be useful if you want to validate the token before you call API in your custom logic (e.g. Access B2C Service API in custom PHP, Access B2C Service API from CX Sales Groovy).

Here are the steps -

1. Base64 Encode the Client ID and Client Secret

Once you create confidential app on IDCS, you can get its Client ID and Secret then you can create the string by concatenating the client ID and client secret with a colon between them like this (clientid:clientsecret)

To generate base64 encoded value, you can use tools like certutil on Windows or website (https://www.base64encode.org/).

The following is an example of encoding from website https://www.base64encode.org/


2. Obtain an Access Token

The next step in this process is to request the access token.

  • Launch a command prompt.
  • Enter the cURL command below, replacing the text in brackets ( < > ) with the appropriate values.

curl -i

-H "Authorization: Basic <base64encoded clientid:secret>"

-H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"

--request POST https://tenant-base-url/oauth2/v1/token

-d "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__"

  • Copy the access_token value from the response. Make sure to copy only the actual token, which is the access_token value between the quotation marks.

C:\curl\curl-7.69.1-win64-mingw\bin>curl -H "Authorization: Basic ZDczZDE1ODFkMTQwNDUyZjhlNzlmMDAzNjcyMDk3MTE6NDFiMTU5YTYtZTQxMy00MjJhLWE4ZDQtODY4NjFlNjczOGQ2" -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" --request POST https://tenant-base-url/oauth2/v1/token -d "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__"
{"access_token":"eyJ4NXQjUzI1NiI6Ii1ob2VIaG9UYmxBYVJmMnJhb21rS0xhelh0cWh0TDBYZUhmTW1jeTUxSDAiLCJ4NXQiOiJqT1FXVzFpRWxrMERsNHdSRWtNWnpFckFoNjgiLCJraWQiOiJTSUdOSU5HX0tFWSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJkNzNkMTU4MWQxNDA0NTJmOGU3OWYwMDM2NzIwOTcxMSIsInVzZXIudGVuYW50Lm5hbWUiOiJpZGNzLTc1MWRlMjkzODRiMTRmZThi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DAyYjgwNzFmMzQiLCJjbGllbnRfbmFtZSI6Ik9TdkNfVFNUMiIsInRlbmFudCI6ImlkY3MtNzUxZGUyOTM4NGIxNGZlOGIyNzFmMWZiNzJjNDFhZWQiLCJqdGkiOiI5MmE3NGVhMC01NjVhLTQ0MDgtYmMwZS03ZmVlM2Q3MDAyY2QifQ.FQj5kvieS6FLIfrE2zPa2fTQ5YgmJAA0SRH786s1bget8NG8rK_51c9lFvlhOra8-Yd_kQTECvaG7t9lOQIXYCG0zhVU7GtZFOooqowZcBSewU_UKwR2iJv5zlDw8FIMbIVTottNKiwO9lAhLkgTPiNaOORB8_vq6DfiJQNfNQ2h8GPQMpxOAjNiyQHqgFsUQpLTSLoBg_kbCfHcLeKHlOz3uO3eiX6a1Kzct3GRkuB1nAiJW61e2VFZwycFcMZOMBpxBRWjIlRA9wQZ8su9_4ylEpkQL97YRqMO3G6NqeMhh9mTUIfVtilxQJD-7ja8_ZnNBTqr9gJsPF-jcmiqoQ","token_type":"Bearer","expires_in":3600}


3. Make a REST Request to the B2C Service environment
After you obtain the OAuth access token, you can use the token in a cURL command to send a REST request to the Oracle B2C Service REST API. The following command returns metadata in your Oracle B2C Service instance.


curl -X GET -H "Content-Type:application/scim+json" -H "OSvC-CREST-Application-Context:123" -H "Authorization: Bearer eyJ4NXQjUzI1NiI6Ii1ob2VIaG9UYmxBYVJmMnJhb21rS0xhelh0cWh0TDBYZUhmTW1jeTUxSDAiLCJ4NXQiOiJqT1FXVzFpRWxrMERsNHdSRWtNWnpFckFoNjgiLCJraWQiOiJTSUdOSU5HX0tFWSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJkNzNkMTU4MWQxNDA0NTJmOGU3OWYwMDM2NzIwOTcxMSIsInVzZXIudGVuYW50Lm5hbWUiOiJpZGNzLTc1MWRlMjkzODRiMTRmZThiMjcxZjFmYjcyYzQxYWVkIiwic3ViX21hcHBpbmdhdHRyIjoidXNlck5hbWUiLCJwcmltVGVuYW50Ijp0cnVlLC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NGIxNGZlOGIyNzFmMWZiNzJjNDFhZWQiLCJqdGkiOiI5MmE3NGVhMC01NjVhLTQ0MDgtYmMwZS03ZmVlM2Q3MDAyY2QifQ.FQj5kvieS6FLIfrE2zPa2fTQ5YgmJAA0SRH786s1bget8NG8rK_51c9lFvlhOra8-Yd_kQTECvaG7t9lOQIXYCG0zhVU7GtZFOooqowZcBSewU_UKwR2iJv5zlDw8FIMbIVTottNKiwO9lAhLkgTPiNaOORB8_vq6DfiJQNfNQ2h8GPQMpxOAjNiyQHqgFsUQpLTSLoBg_kbCfHcLeKHlOz3uO3eiX6a1Kzct3GRkuB1nAiJW61e2VFZwycFcMZOMBpxBRWjIlRA9wQZ8su9_4ylEpkQL97YRqMO3G6NqeMhh9mTUIfVtilxQJD-7ja8_ZnNBTqr9gJsPF-jcmiqoQ" https://osvc.custhelp.com/services/rest/connect/v1.4/metadata-catalog


That's it!


Note - You can also refer to Oracle Doc for cross-reference -

Let me know if any feedback.


Thanks,
Adam Liu





Comments

  1. BlockchainX's expert developers have answers for you with state of the art Erc20 token generator. Give your Dapps the power of ethereum based ERC20 token and integrate secured crypto payment systems.erc20 token generator

    ReplyDelete
  2. The future is cross-chain and you can do that now a token bridge. A cross-chain bridge let's you launch your token on multiple blockchains and allow users send your tokens between chains. Launch your token on any EVM blockchain with our cross-chain bridge.Build a cross chain bridge

    ReplyDelete
  3. You can create a TRC20 or TRC721 Token through our Tron token development services and they will work seamlessly with their Ethereum counterparts.

    ReplyDelete
  4. The Token Migration platform helps projects upgrade their old tokens to new tokens. In essence, if your old token has any flaws or if you want to add some additional features, you can create an entirely new token and users can swap their old tokens with your new tokens through the migration contract.

    ReplyDelete
  5. The migration platform works similarly to a DEX without the Automated Market Maker system. The New or V2 tokens are stored inside the migration smart contract and users can simply connect their web3 wallets to trustlessly migrate their tokens.Token Migration

    ReplyDelete
  6. Fantastic, I Loved it you wrote very good article. I got what you intend; thankyou you for putting up; I also remember one such article about Solana Blockchain Perks Has The Answer To Everything. It is awesome!

    ReplyDelete

  7. I read a lot of blog entries and had never come across such a topic before. I truly enjoy the topic of the blogger's bucket list you chose. This is a very useful article. Nowadays, new technology in the entertainment business allows individuals to unwind and enjoy their leisure time. The latest technology has revolutionized daily entertainment. - LBM Blockchain Solutions

    ReplyDelete
  8. I know this is an amazing post, it defines the true value of your knowledge. In fact, running a business is not common. People keep running to drive more business and generate more customers. At LBM Blockchain Solutions which is best Blockchain development company in Mohali , you can maintain a leading position with Blockchain development in Mohali . keep it up. I really think this article is amazing, I can't describe it in words. Also, if you need best crypto exchange development company in Mohali
    , do not delay in shaking hands with LBM Blockchain Solutions.

    ReplyDelete
  9. Thanks a lot! Nice post!
    But nowadays, thanks to the hype around NFTs, cryptocurrencies, and blockchain tech in general, many people ask what does NFT development service mean.

    ReplyDelete
  10. Our Dapp development services help you create robust and scalable decentralized applications. As a Dapp development company with several years of experience, we provide you with industry-leading blockchain architects, smart contract developers, and web3 developers.
    DApp Development Solutions
    Build decentralized app

    ReplyDelete

Post a Comment

Popular posts from this blog