Curl call to get token from private cloud throws error

Not applicable

hi,

Trying to get the token using curl from private cloud, but throws the below error, how to get it correct. :

{ "fault": { "faultstring": "JavaScript execution failed: \"_\" is not defined.: ReferenceError: \"_\" is not defined.\n at sendError (/organization/environment/api/api/controllers/volos-oauth.js:132)\n at /organization/environment/api/api/controllers/volos-oauth.js:56\n at /organization/environment/api/node_modules/volos-oauth-common/lib/oauth.js:237\n at /organization/environment/api/node_modules/volos-oauth-common/lib/oauth.js:279\n at checkResultError (/organization/environment/api/node_modules/volos-oauth-apigee/lib/apigeeoauthimpl.js:466)\n at /organization/environment/api/node_modules/volos-oauth-apigee/lib/apigeeoauthimpl.js:435\n at /organization/environment/api/node_modules/apigee-access/lib/oauth.js:56\n", "detail": { "errorcode": "scripts.node.ScriptExecutionError" } } }

0 9 311
9 REPLIES 9

Not applicable

The above error mentions the '_' not defined in grant type. I did follow how it was mentioned in the doc.

curl -i -X POST --user 4t8X137pOUUtMR7wag3M1yZTcRxeK:RAcOFVOvO0jns"http://<org>-<env>.apigee.net/edgemicro-auth/token"-d '{"grant_type": "client_credentials"}'-H "Content-Type: application/json"

But if i remove the '_' from "client_credentials" ie, {"grant_type": "client credentials"}

It shows the below error:

{ "error_description": "Unsupported grant type", "error": "unsupported_grant_type" }

Hi Apurba,

Have you tried the edgemicro token command? Give that a shot, and let me know if you see similar behavior.

-Matt

Yes, via edgemicro cli it works fine.

I'd recommend using that tool then. It's definitely easier to retrieve tokens using that. Let me know if you have any other questions.

-Matt

hey @Matt

I have few 🙂

FYI : We wanted the frontend application team to request curl when the token expires, so we wanted to give them the curl call rather than the cli.

Is there any other way to implement that?

But why is it not working? I dont see any query on this, that must mean it is working fine in other's case. Why not here then.

And also the token decode command, it shows the below error

[root@AUS-LNAAPGD-004 .edgemicro]# edgemicro token decode -f token.jwt
current nodejs version is v4.6.0
current edgemicro version is 2.2.4-beta
module.js:327
    throw err;
    ^


Error: Cannot find module '../api/helpers/jwt'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Token.decodeToken (/usr/local/lib/node_modules/edgemicro/cli/lib/token.js:23:15)
    at Command.<anonymous> (/usr/local/lib/node_modules/edgemicro/cli/cmd-token.js:15:13)
    at Command.listener (/usr/local/lib/node_modules/edgemicro/node_modules/commander/index.js:301:8)
    at emitTwo (events.js:87:13)
    at Command.emit (events.js:172:7)
    at Command.parseArgs (/usr/local/lib/node_modules/edgemicro/node_modules/commander/index.js:615:12)

I have tried to create the token.jwt file but it doesn't recognize the option, so i had just copied the token in the file in above case

[root@AUS-LNAAPGD-004 .edgemicro]# edgemicro token get -o wiley -e common-dev -f token.jwt
current nodejs version is v4.6.0
current edgemicro version is 2.2.4-beta


  error: unknown option `-f'

The edgemicro token command is for generating oauth tokens to hit your API. Are you trying to generate a jwt, or a client token? I took your curl below and tossed some spaces in. Was that the command you were trying to use without the spaces?

curl -i -X POST --user 4t8X137pOUUtMR7wag3M1yZTcRxeK:RAcOFVOvO0jns "http://<org>-<env>.apigee.net/edgemicro-auth/token" -d '{"grant_type": "client_credentials"}' -H "Content-Type: application/json"

hi Matt,

It worked, a space was getting added in the client secret 😞 . Thats what threw the error.

I was trying to generate the jwt. And how do you generate the client token?

And regarding jwt decode:

I am trying to run the below steps to

  1. create the token.jwt -- $edgemicro token get -o wiley -e common-dev -i <client id> -s <secret> -f token.jwt
  2. decode the token.jwt --$edgemicro token decode -f token.jwt.

And it shows the error as above -- error: unknown option `-f'

Please let me know if i am not doing it correctly.

thanks,

apurba.

Hi Apurba,

The command you are using to get a token doesn't generate a JWT. Are you following a docs article that is saying this is the way to generate a jwt? If so can you point me in the direction of the docs article?

-Matt

hi Matt, sorry for the delay.

Nah, the commands i mentioned previously, i wanted to decode the jwt not create.

I was able to create the jwt, but i wanted to see the jwt information.

Also how do i change the expiry time for the jwt?

Thanks,

apurba.