From b822840cd1c5062420f612051ef77265da5fda93 Mon Sep 17 00:00:00 2001 From: Thomas Brinkmann Date: Wed, 1 Jun 2022 17:49:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9EAuthorization=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.md | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Authorization.md diff --git a/Authorization.md b/Authorization.md new file mode 100644 index 0000000..ca67a88 --- /dev/null +++ b/Authorization.md @@ -0,0 +1,100 @@ +## **Authorization** + + +[Zurück zur Übersicht](index.md) + +--- + +* Authorization Header +* Auth Middleware +* IP Restrictions + +### **Authorization Header** +The Auhorization header will be used to identify the client/API that connect to it. + +### **PHP** +Example to set the Header with PHP-Curl: +```php + "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 + +```bash +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. +```go +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 + +```javascript +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); +}); +``` \ No newline at end of file