A service agnostic authentication micro-server with TikTok and Twitch auth integration.
This service is meant to work behind a firewall and should not be exposed to the public network. Instead a separate public facing api should interact with this service.
Start development server
pnpm devRun production server
pnpm build
pnpm startOr with docker compose
docker compose build
docker compose upMake sure to run migrations to create or migrate the db
pnpm build
pnpm migrateThis service uses redis. If you are using docker compose redis is included and you don't need REDIS_URL
A .env file with the following keys is required
PORT={{ PORT }}
ENCRYPTION_KEY={{ ENCRYPTION_KEY }}
SQLITE_DB_PATH={{ SQLITE_DB_PATH }}
TOKEN_ISSUER={{ TOKEN_ISSUER }}
REDIS_URL={{ REDIS_URL }}An app represent an application interacting with the Auth service. An app contains multiple external services for authenticating and connecting like tiktok or twitch.
GET /app
// Response
200
[
{
id: string,
}
]GET /app/:appId
// Response
200
[
{
type: string,
clientSecret: string,
clientId: string
}
]POST /app/:appId
[
{
type: string,
clientSecret: string,
clientId: string
}
]
// Response
201POST /:appId/authenticate/authUrl
Content-Type: application/json
{
redirectUrl: string,
scopes: Array<string>
}
// Response
200
{
authUrl: string
}Creates an account if it does not exists on db.
If shouldUpsertConnection is set to true then it will also create a connection to the equivalent service or update a connection if it exists. So in the case you require to hold an access token for the same service you authenticate, this should save you having to re-authenticate the user to add a connection.
POST /:appId/authenticate/:externalServiceId
Content-Type: application/json
{
code: string,
redirectUrl: string,
shouldUpsertConnection?: boolean
}
// Response
200
{
token: string // jwt token
}
// The response jwt will have the following format:
user: {
app: string,
id: number,
provider: {
type: string,
userId: string,
userLogin: string,
profileImageUrl: string,
displayName: string
}
}POST /token/verify
Content-Type: application/json
{
token: string
}
// Response
200
401 - When token is not validPOST /:appId/user/:userId/connection/:connectionTypeId
Content-Type: application/json
{
code: string,
redirectUrl: string
}
// Response
201GET /:appId/user/:userId/connections
// Response
200
[{
displayName: string,
profileImageUrl: string,
refreshToken: string,
token: string,
type: 'tiktok' | 'twitch' | 'youtube',
userId: string,
expiresInMs: number
}]DELETE /:appId/user/:userId/connection/:connectionTypeId
// Response
200This invalidates the current access_token and refreshes the token in the database. This should be called in the unfortunate case of leaking the access_token.
DELETE /:appId/user/:userId/connection/:connectionTypeId/revoke
// Response
200