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
Info |
---|
Falls du noch keinen Schlüssel erhalten hast, melde dich auf hello@micromate.ai. |
Zum signieren des JWT verwendest du am besten eine bestehende Bibliothek:
Technologie | Library |
---|---|
NodeJS | |
PHP |
...
Code Block | ||
---|---|---|
| ||
import * as jsonwebtoken from 'jsonwebtoken'; import fs from "fs"; import {JWTPrivateKey} from "./JWTPrivateKey"; export interface JWTPrivateKey { type: string, keyId: string, key: string, userId: string } public static createJWTcreateSignedJWT(): string { // Read the private key const jwtFilerawPrivateKey = fs.readFileSync('./jwtprivateKey.json', 'utf8'); const jwtDataprivateKey = JSON.parse(jwtFilerawPrivateKey) 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); // Create a return jsonwebtoken.sign(JWT token const jwtToSign = { iss: jwtDataprivateKey.userId, sub: jwtDataprivateKey.userId, aud: 'https://micromate-q4ee42.zitadel.cloud', iat: validFrom, exp: expiration }, jwtData; // Sign and return the token return jsonwebtoken.sign(jwtToSign, privateKey.key, {algorithm: 'RS256', keyid: jwtDataprivateKey.keyId}); } |