Wir unterstützen als Client Authentifizeriung die Private Key JWT-Methode. D.h. damit du die Public API von Micromate aufrufen kannst, musst du ein JWT erstellen und dieses mit dem Schlüssel welchen du von uns erhalten hast signieren.
Verwende dazu am besten bereits vorhandene Libraries:
Technologie | Library |
---|---|
NodeJS | |
PHP |
Beispiel NodeJS
Folgend eine Beispielimplementation in Typescript verwendet in einer NodeJS-Umgebung:
import * as jsonwebtoken from 'jsonwebtoken'; import moment from "moment"; import fs from "fs"; import {JWTPrivateKey} from "./JWTPrivateKey"; export interface JWTPrivateKey { type: string, keyId: string, key: string, userId: string } public static createJWT(): string { const jwtFile = fs.readFileSync('./jwt.json', 'utf8'); const jwtData = JSON.parse(jwtFile) as JWTPrivateKey; // Valid from now minus 10 seconds const validFrom: number = Math.floor(Date.now() / 1000) - 10; // Expiration 1 hour after now const expiration: number = Math.floor(Date.now() / 1000) + (60 * 60); return jsonwebtoken.sign({ iss: jwtData.userId, sub: jwtData.userId, aud: 'https://micromate-q4ee42.zitadel.cloud', iat: validFrom, exp: expiration }, jwtData.key, {algorithm: 'RS256', keyid: jwtData.keyId}); }