Issue:
Convert OpenID curl command to YAML for AAP or JavaScript for NodeJS or vRO:
Adapted cURL code from OpenID documentation:
$ curl \
--request POST \
--data "grant_type=client_credentials" \
--data "client_id=myClient" \
--data "client_secret=reallygoodpassword" \
--data "scope=write" \
"https://openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2"
YAML Code Equivalent:
- name: 'https://openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2'
uri:
url: ''https://openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2'
method: POST
body:
grant_type: client_credentials
client_id: myClient
client_secret: reallygoodpassword
scope: write
body_format: form-urlencoded
headers:
Content-Type: application/x-www-form-urlencoded
register: result
JavaScript Fetch:
fetch('https://openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2', {
method: 'POST',
body: new URLSearchParams({
'grant_type': 'client_credentials',
'client_id': 'myClient',
'client_secret': 'reallygoodpassword',
'scope': 'write'
})
});
JavaScript XHR:
const data = new URLSearchParams({
'grant_type': 'client_credentials',
'client_id': 'myClient',
'client_secret': 'reallygoodpassword',
'scope': 'write'
});
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('POST', 'openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
console.log(xhr.response);
};
xhr.send(data);
JavaScript / NodeJS HTTP:
import https from 'https';
const options = {
hostname: 'openam.mindwatering.net:8443',
path: '//as/oauth2/realms/root/authorization.oauth2',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
const req = https.request(options, function (res) {
const chunks = [];
res.on('data', function (chunk) {
chunks.push(chunk);
});
res.on('end', function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(new URLSearchParams({
'grant_type': 'client_credentials',
'client_id': 'myClient',
'client_secret': 'reallygoodpassword',
'scope': 'write'
}).toString());
req.end();
JavaScript / NodeJS Request:
(deprecated)
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'grant_type=client_credentials&client_id=myClient&client_secret=reallygoodpassword&scope=write';
var options = {
url: 'https://'openam.mindwatering.net:8443/as/oauth2/realms/root/authorization.oauth2',
method: 'POST',
headers: headers,
body: dataString
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
previous page
|