aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/token.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users/token.ts')
-rw-r--r--server/controllers/api/users/token.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/server/controllers/api/users/token.ts b/server/controllers/api/users/token.ts
index 694bb0a92..b405ddbf4 100644
--- a/server/controllers/api/users/token.ts
+++ b/server/controllers/api/users/token.ts
@@ -1,13 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as RateLimit from 'express-rate-limit' 2import * as RateLimit from 'express-rate-limit'
3import { v4 as uuidv4 } from 'uuid'
4import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { buildUUID } from '@server/helpers/uuid'
5import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
6import { getAuthNameFromRefreshGrant, getBypassFromExternalAuth, getBypassFromPasswordGrant } from '@server/lib/auth/external-auth' 6import { getAuthNameFromRefreshGrant, getBypassFromExternalAuth, getBypassFromPasswordGrant } from '@server/lib/auth/external-auth'
7import { handleOAuthToken } from '@server/lib/auth/oauth' 7import { handleOAuthToken } from '@server/lib/auth/oauth'
8import { BypassLogin, revokeToken } from '@server/lib/auth/oauth-model' 8import { BypassLogin, revokeToken } from '@server/lib/auth/oauth-model'
9import { Hooks } from '@server/lib/plugins/hooks' 9import { Hooks } from '@server/lib/plugins/hooks'
10import { asyncMiddleware, authenticate } from '@server/middlewares' 10import { asyncMiddleware, authenticate, openapiOperationDoc } from '@server/middlewares'
11import { ScopedToken } from '@shared/models/users/user-scoped-token' 11import { ScopedToken } from '@shared/models/users/user-scoped-token'
12 12
13const tokensRouter = express.Router() 13const tokensRouter = express.Router()
@@ -19,10 +19,12 @@ const loginRateLimiter = RateLimit({
19 19
20tokensRouter.post('/token', 20tokensRouter.post('/token',
21 loginRateLimiter, 21 loginRateLimiter,
22 openapiOperationDoc({ operationId: 'getOAuthToken' }),
22 asyncMiddleware(handleToken) 23 asyncMiddleware(handleToken)
23) 24)
24 25
25tokensRouter.post('/revoke-token', 26tokensRouter.post('/revoke-token',
27 openapiOperationDoc({ operationId: 'revokeOAuthToken' }),
26 authenticate, 28 authenticate,
27 asyncMiddleware(handleTokenRevocation) 29 asyncMiddleware(handleTokenRevocation)
28) 30)
@@ -78,9 +80,10 @@ async function handleToken (req: express.Request, res: express.Response, next: e
78 } catch (err) { 80 } catch (err) {
79 logger.warn('Login error', { err }) 81 logger.warn('Login error', { err })
80 82
81 return res.status(err.code || 400).json({ 83 return res.fail({
82 code: err.name, 84 status: err.code,
83 error: err.message 85 message: err.message,
86 type: err.name
84 }) 87 })
85 } 88 }
86} 89}
@@ -104,7 +107,7 @@ function getScopedTokens (req: express.Request, res: express.Response) {
104async function renewScopedTokens (req: express.Request, res: express.Response) { 107async function renewScopedTokens (req: express.Request, res: express.Response) {
105 const user = res.locals.oauth.token.user 108 const user = res.locals.oauth.token.user
106 109
107 user.feedToken = uuidv4() 110 user.feedToken = buildUUID()
108 await user.save() 111 await user.save()
109 112
110 return res.json({ 113 return res.json({