Skip to content

Commit

Permalink
feat: update interledger/openapi, handle openapi validator errors in …
Browse files Browse the repository at this point in the history
…middleware
  • Loading branch information
njlie committed May 15, 2024
1 parent d04092a commit 85a7724
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@graphql-tools/schema": "^10.0.3",
"@interledger/http-signature-utils": "2.0.2",
"@interledger/open-payments": "6.8.0",
"@interledger/openapi": "1.2.1",
"@interledger/openapi": "2.0.1",
"@koa/cors": "^5.0.0",
"@koa/router": "^12.0.0",
"ajv": "^8.12.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export function initIocContainer(
container.singleton('logger', async (deps: IocContract<AppServices>) => {
const config = await deps.use('config')
const logger = createLogger({
level: config.logLevel
level: config.logLevel,
redact: [
'grant.continueToken',
'headers.authorization',
'accessToken.value',
'requestBody.access_token'
]
})
return logger
})
Expand Down
19 changes: 16 additions & 3 deletions packages/auth/src/shared/gnapErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppContext } from '../app'

import { OpenAPIValidatorMiddlewareError } from '@interledger/openapi'
export enum GNAPErrorCode {
InvalidRequest = 'invalid_request',
InvalidClient = 'invalid_client',
Expand Down Expand Up @@ -54,17 +54,30 @@ export async function gnapServerErrorMiddleware(
message: err.message,
requestBody: ctx.request.body
},
'Received error when handling GNAP request'
'Received error when handling Open Payments GNAP request'
)

ctx.throw(err.status, err.code, {
error: { code: err.code, description: err.message }
})
} else if (err instanceof OpenAPIValidatorMiddlewareError) {
const finalStatus = err.status || 400

logger.info(
{
...baseLog,
message: err.message,
status: finalStatus
},
'Received OpenAPI validation error when handling Open Payments GNAP request'
)

ctx.throw(finalStatus, err.message)
}

logger.error(
{ ...baseLog, err },
'Received unhandled error in GNAP request'
'Received unhandled error in Open Payments GNAP request'
)
ctx.throw(500)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/auth/src/signature/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export async function tokenHttpsigMiddleware(
}

if (!accessToken.grant) {
const logger = await ctx.container.use('logger')
logger.error(
`access token with management id ${ctx.params['id']} has no grant associated with it.`
)
throw new GNAPServerRouteError(
500,
GNAPErrorCode.RequestDenied,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85a7724

Please sign in to comment.