cancel
Showing results for 
Search instead for 
Did you mean: 

Getting {“error”:“Not authorized”} when trying to call BlockChain RESTFul interface on Cloud Foundry

former_member377261
Discoverer
0 Kudos

Hi all,

I have tried to post the same question below at stackoverflow but nothing yet that helps me in my situation.

https://stackoverflow.com/questions/48243720/cloud-foundry-oauth-token-retrieved-but-get-errornot-au...

I have developed working "chaincode" in Go and deployed to cloud platform. I can interact / interface with this chaincode happily once logged in manually.

From what I see SAP is using Cloud Foundry to house the blockchain / hyperledger services.

In my situation I login to a cloud foundry instance with a valid user name / password at https://login.cf.us10.hana.ondemand.com/login

That then redirects me to another host "blockchain-cockpit.cfapps.us10.hana.ondemand.com" where I can successfully call the RESTful API's in question via the "cockpit" provided on the web page.

My goal here is to be able to call the RESTful services on "blockchain-cockpit.cfapps.us10.hana.ondemand.com" using an OAuth token.

So I go to the command line to get an OAuth token using the following command:

curl -v -XPOST -H "Application/json" -u "cf:" --data "username=<username>&password=<password>&client_id=cf&grant_type=password&response_type=token" https://login.cf.us10.hana.ondemand.com/oauth/token

And that happily passes me back what *seems to be a valid" token

For example:

{"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleS0xIiwidHlwIjoiSldUIn0.eyJqdGkiOiJmZTY1NjYyOTM3YTk0Nzc0YTUyYmM5MzRiYzU5MjRjOCIsInN1YiI6ImMxYzcyZTcyLWI3OGUtNDAyYy1iZTBjLWQ3MDUyNzYzZmZmYiIsInNjb3BlIjpbIm9wZW5pZCIsInVhYS51c2VyIiwiY2xvdWRfY29udHJvbGxlci5yZWFkIiwicGFzc3dvcmQud3JpdGUiLCJjbG91ZF9jb250cm9sbGVyLndyaXRlIl0sImNsaWVudF9pZCI6ImNmIiwiY2lkIjoiY2YiLCJhenAiOiJjZiIsImdyYW50X3R5cGUiOiJwYXNzd29yZCIsInVzZXJfaWQiOiJjMWM3MmU3Mi1iNzhlLTQwMmMtYmUwYy1kNzA1Mjc2M2ZmZmIiLCJvcmlnaW4iOiJsZGFwIiwidXNlcl9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ox1jQRqoMuAS_VSGTiHAnLoOPVf7s0Y09wKuIeVwfB2UHFhs7UtKM7egJGKeZFAOcHAZNL8qbyqkRi0bkOOEMD0mqvEvMHEeS1o5KmYQ7zrxyNgQJgwJ98zMgOzHmC3NQ8o_sNZKTurxNqaPFsbmoB2tCoI9AkfaVdeDOd8tiY6XBAu5h76O7pag9RV4ch_nmViAPYwpD_ZxvwhB_3X0oqSKKNKzZaLW9ONip7yBmMhCub48D_zT26bOKUIYenO1LAV5aHjufsut7YxWBadrPSpGF-Oz6VYYeDqCerf7F8-rdA-RZYGUQBK-weTLJAfbQPn6CgTO4","expires_in":599,"scope":"openid uaa.user cloud_controller.read password.write cloud_controller.write","jti":"fe65662937a94774a52bc934bc5924c8"}* Connection #0 to host login.cf.us10.hana.ondemand.com left intact


Assuming I now have a valid token I then try POST using POSTMAN and set the HTTP header:

Authorization: Bearer #access token from above#


As mentioned before I am POSTing to "blockchain-cockpit.cfapps.us10.hana.ondemand.com" and not the host I got the token from so not sure if that is a major issue here.

PostMan keeps giving me this error

{ "error": "Not authorized" }

I then try the same using CURL using the following command:

 curl -H "Authorization: Bearer <token>" -X POST https://blockchain-cockpit.cfapps.us10.hana.ondemand.com/<remaining rest api> --data "test data"

I get the exact same issue:

{"error":"Not authorized"}

So my issue in my mind is if I login manually and interact with the api's on the site it works perfectly, yet when I apparently get a valid token and try post to the restful api's it keep failing?

Any ideas? I would really appreciate some help on this 😉

Thanks

Lynton

aztlan
Explorer
0 Kudos

Hello, Iam presenting the error Unauthorized in the test chaincode on the sap cloud platform cockpit. Did you was able to solve this error and how?

Accepted Solutions (0)

Answers (0)