2
Autorisierung
Thomas Brinkmann edited this page 3 years ago
Autorisierung
- Authorization Header
- IP Restrictions
Authorization Header
Der Auhorization-Header wird verwendet, um den Client/die API zu identifizieren, der/die sich damit verbindet.
PHP
Example to set the Header with PHP-Curl:
<?php
$url = "https://api.domain.de/api/v2/PATH";
$header = [
"Content-Type" => "application/json",
"x-token" => "YOUR-TOKEN" // The required Auth. Header.
];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$resp = curl_exec($curl);
// This Example is just to show how to set headers.
?>
cURL
Example to set the Header with a cURL request
curl --location --request GET 'https://api.domain.de/api/v2/PATH' \
--header 'x-token: YOUR-TOKEN' \
--header 'Content-Type: application/json'
GoLang
Example to set the headers with GOLang.
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.domain.de/api/v2/PATH"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("x-token", "YOUR-TOKEN")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
NodeJS
Example to set the headers with NodeJS
var request = require('request');
var options = {
'method': 'GET',
'url': 'http://api.domain.de/api/v2/PATH',
'headers': {
'x-token': 'YOUR-TOKEN',
'Content-Type': 'application/json'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
IP Restrictions
Jeder Client der die API ansteuert muss von einer IP-Adresse stammen die eingetragen ist. Nicht eingetragene IP-Adressen werden abgelehnt. Es wird später möglich sein weitere User Accounts zu definieren um Unterkonten zu erstellen welche ebenfalls die API verwenden dürfen.