Integration

This page describes how you can integrate with the API gateway into your own backend

Introduction

The API gateway can receive audio file, decode and return transcription. It also provides authenticate service that helps authenticate user account or protect your backend endpoints without provide your own implementation

With the help of API gateway, your backend delegates user authentication part to the API gateway and you don't need to implement your user authentication your own.

See below steps for setup to get your app integrates with the API gateway.

Register your app to the API gateway

First login to https://gateway-app.speechlab.sg -> Select Applications in the left sidebar -> Click Create to create your application. Type in your App name and click Save. If you're account has admin role, then you can select other queue for your app otherwise it'll default to normal queue.

Queue: all users registered through your app can only submit audio file to that queue

To check your account's role, hover your avatar at top right corner

After creating, you'll receive your app ID, app Secret and a public Key. You should save these information for later use, note that app secret will be shown only once , so remember to save it. For Public Key you should download it.

Next in your code, when you register new account or login with the API gateway you should provide your App ID and App Secret. See example below:

Login from your app to the API gateway

POST https://gateway.speechlab.sg/auth/login

Path Parameters

Request Body

Register from your app to the API gateway

POST https://gateway.speechlab.sg/auth/register

Path Parameters

Request Body

After login, you'll receive an accessToken that is signed only to use for your app. Next time when your user try to use your resources, they need to provide it request header (Authorization: Bearer <accessToken>).

And when your user access your protected endpoints, you should verify them using the Public Key (which you got from the early step above). Base on your language (Python/NodeJS,...) you should use correct version of jsonwebtoken library to verify user Access Token using Public Key.

Below are example using jsonwebtoken in NodeJS.

const jsonwebtoken = require('jsonwebtoken')
const fs = require('fs')

jsonwebtoken.verify('access token', fs.readFileSync('./path_to_public_key'), {
  ignoreExpiration: false,
  ignoreNotBefore: false,
  algorithms: ['RS256'],
  issuer: 'api gateway url which you are working with', // Eg: https://gateway.speechlab.sg
  audience: 'Your app ID',
})

Access Token is signed using RS256 algorithm

And after verification, if access token is valid, they will have permission to access your endpoints

Last updated