I am working on the OAuth2.0 Authorising code grant type.
I have received the OAuthorising code in the query param of response location header.It is a 302 redirect .
I am attaching the trace console.
Everything is working fine.
The url in response location header is https://hsbhattacharjee25-eval-test.apigee.net/redirecturl?code=lH1Q8bBm≻ope=.
I want to extract the code out and use it later in the flow.
I could not find anything in the doc to extract query param from location response header.
Can anybody explain the code for the same?
Solved! Go to Solution.
Maybe the easiest way would be to use a JS callout and just parse the string.
Maybe something like this:
var v = context.getVariable('response.header.location'); var ix = (v == null)? -1 : v.indexOf('?'); if (ix != -1) { var query = v.substring(ix + 1); var params = query.split('&'); params.forEach(function(pair) { var parts = pair.split('=', 2); if (parts[0] == 'code') { context.setVariable('savedcode', parts[1]); } }); }
Maybe the easiest way would be to use a JS callout and just parse the string.
Maybe something like this:
var v = context.getVariable('response.header.location'); var ix = (v == null)? -1 : v.indexOf('?'); if (ix != -1) { var query = v.substring(ix + 1); var params = query.split('&'); params.forEach(function(pair) { var parts = pair.split('=', 2); if (parts[0] == 'code') { context.setVariable('savedcode', parts[1]); } }); }
Is there other easier way to do it like in extract variable policy?
Dino-at-Google please explain the code a little bit.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |