Deutsch |
---|
Die Authentifizierung ist der erste Schritt der programmatischen Beschaffung eines JSON-Web-Tokens zur Verwendung mit der API. - Endpunkt:
/cloud-service-auth/auth - Methode:
POST - Body:
Codeblock |
---|
{
name, // your@mail.com
password,
lifetime: 1800000, // millis -> 30mins
code: null,
termsOfUse: null // TODO
} |
Codeblock |
---|
const getInitialToken = () => {
const headers = new fetch.Headers({
"Content-Type": "application/json;charset=UTF-8"
});
return fetch(config.baseurl + "/cloud-service-auth/auth", {
method: "POST",
headers: headers,
body: JSON.stringify({
name,
password,
lifetime: 1800000, // millis -> 30mins
code: null,
termsOfUse: null
})
}).then(resp => resp.json());
}; |
Mit dem aus der Authentifizierungsanforderung resultierenden Token können wir nun dieses Token erweitern, um ein Token mit einem Kontext zu erhalten, das bei weiteren API-Anforderungen verwendet werden kann. - Endpunkt:
/cloud-service-auth/auth - Methode:
POST - Body:
Codeblock |
---|
{
accountIds: [ /* list of account UUIDs */ ]
} |
Codeblock |
---|
const upgradeToken = (initialToken, ids) => {
if (!initialToken.value) {
throw new Error("Missing JWT");
}
const headers = new fetch.Headers({
"Content-Type": "application/json;charset=UTF-8",
"Authorization": "Bearer " + initialToken.value
});
return fetch(config.baseurl + "/cloud-service-auth/auth", {
method: "POST",
headers: headers,
body: JSON.stringify({
accountIds: ids
})
}).then(resp => {
if (resp.ok) {
// do something with the token here
} else {
console.log(resp);
throw new Error("Error upgrading JWT");
}
});
}; |
|
...
Authentication is the first step of programmatically obtaining an JSON Web Token to use with the API.
- Endpoint:
/cloud-service-auth/auth
- Method:
POST
- Body:
Codeblock |
---|
{
name, // your@mail.com
password,
lifetime: 1800000, // millis -> 30mins
code: null,
termsOfUse: null // TODO
} |
JavaScript (NodeJS) Example:
Codeblock |
---|
const getInitialToken = () => {
const headers = new fetch.Headers({
"Content-Type": "application/json;charset=UTF-8"
});
return fetch(config.baseurl + "/cloud-service-auth/auth", {
method: "POST",
headers: headers,
body: JSON.stringify({
name,
password,
lifetime: 1800000, // millis -> 30mins
code: null,
termsOfUse: null
})
}).then(resp => resp.json());
}; |
Authorization
With the resulting token from the Authentication request, we can now upgrade this token to obtain a token with a context, to be used with further API requests.
- Endpoint:
/cloud-service-auth/auth
- Method:
POST
- Body:
Codeblock |
---|
{
accountIds: [ /* list of account UUIDs */ ]
} |
JavaScript (NodeJS) Example:
Codeblock |
---|
const upgradeToken = (initialToken, ids) => {
if (!initialToken.value) {
throw new Error("Missing JWT");
}
const headers = new fetch.Headers({
"Content-Type": "application/json;charset=UTF-8",
"Authorization": "Bearer " + initialToken.value
});
return fetch(config.baseurl + "/cloud-service-auth/auth", {
method: "POST",
headers: headers,
body: JSON.stringify({
accountIds: ids
})
}).then(resp => {
if (resp.ok) {
// do something with the token here
} else {
console.log(resp);
throw new Error("Error upgrading JWT");
}
});
}; |