-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user-tokens): user tokens api (#428)
* feat(user-tokens): user tokens api * fix inject watch script * it just works * fix version bug when legacy disabled * return id also * don't always reload * fix * anotha one * version bumps * bump webchat
- Loading branch information
1 parent
dc1f159
commit 52028f8
Showing
16 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { uuid } from '@botpress/messaging-base' | ||
import { Response } from 'express' | ||
import { ApiManager } from '../base/api-manager' | ||
import { ClientApiRequest } from '../base/auth/client' | ||
import { UserService } from '../users/service' | ||
import { Schema } from './schema' | ||
import { UserTokenService } from './service' | ||
|
||
export class UserTokenApi { | ||
constructor(private users: UserService, private userTokens: UserTokenService) {} | ||
|
||
setup(router: ApiManager) { | ||
router.post('/users/tokens', Schema.Api.Create, this.create.bind(this)) | ||
} | ||
|
||
async create(req: ClientApiRequest, res: Response) { | ||
const userId = req.body.userId as uuid | ||
|
||
const user = await this.users.fetch(userId) | ||
if (!user || user.clientId !== req.clientId) { | ||
return res.sendStatus(404) | ||
} | ||
|
||
const tokenRaw = await this.userTokens.generateToken() | ||
const userToken = await this.userTokens.create(user.id, tokenRaw, undefined) | ||
|
||
res.status(201).send({ id: userToken.id, token: `${userToken.id}.${tokenRaw}` }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Joi from 'joi' | ||
import { ReqSchema } from '../base/schema' | ||
|
||
const Api = { | ||
Create: ReqSchema({ | ||
body: { userId: Joi.string().guid().required() } | ||
}) | ||
} | ||
|
||
const Socket = {} | ||
|
||
export const Schema = { Api, Socket } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters