Machine-to-Machine (M2M) Applications
Enable secure, automated authorization for your backend systems, microservices, and IoT devices, ensuring only trusted apps and devices can access your APIs.
Last updated
Was this helpful?
Was this helpful?
curl --request POST \
--url https://myproject.authgear.cloud/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data resource=IDENTIFIER_OF_API_RESOURCE \
--data client_id=CLIENT_ID \
--data client_secret=CLIENT_SECRETimport urllib.parse
import urllib.request
import json
url = "https://myproject.authgear.cloud/oauth2/token"
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"grant_type": "client_credentials",
"resource": "IDENTIFIER_OF_API_RESOURCE",
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET"
}
encoded_data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url, data=encoded_data, headers=headers, method='POST')
with urllib.request.urlopen(req) as response:
response_status = response.getcode()
response_body = response.read().decode('utf-8')
print("Response Status Code:", response_status)
print("Response Body:", json.loads(response_body))
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func main() {
data := url.Values{}
data.Set("grant_type", "client_credentials")
data.Set("resource", "IDENTIFIER_OF_API_RESOURCE")
data.Set("client_id", "CLIENT_ID")
data.Set("client_secret", "CLIENT_SECRET")
req, _ := http.NewRequest("POST", "https://myproject.authgear.cloud/oauth2/token", strings.NewReader(data.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("Response Status Code:", resp.StatusCode)
fmt.Println("Response Body:", string(body))
}
async function makeRequest() {
const url = "https://myproject.authgear.cloud/oauth2/token";
const data = new URLSearchParams();
data.append("grant_type", "client_credentials");
data.append("resource", "IDENTIFIER_OF_API_RESOURCE");
data.append("client_id", "CLIENT_ID");
data.append("client_secret", "CLIENT_SECRET");
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: data,
});
const responseBody = await response.json();
console.log("Response Status Code:", response.status);
console.log("Response Body:", responseBody);
}
makeRequest();
Authorization: Bearer <access_token>