Skip to content

Commit

Permalink
Write debug messages when authenticating
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellmorten committed Nov 22, 2024
1 parent 34c11ec commit 0158af2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 19 additions & 1 deletion package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
"node": ">= 18"
},
"dependencies": {
"debug": "^4.3.7",
"integreat-adapter-form": "^1.1.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@integreat/ts-dev-setup": "^5.0.4",
"@types/debug": "^4.1.12",
"@types/jsonwebtoken": "^9.0.7",
"@types/node": "^22.9.1",
"integreat": "^1.6.0-rc.28",
Expand Down
9 changes: 8 additions & 1 deletion src/authenticate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debugFn from 'debug'
import formTransformer from 'integreat-adapter-form/transformer.js'
import signJwt from './signJwt.js'
import type { Action, HandlerDispatch } from 'integreat'
Expand All @@ -17,6 +18,8 @@ const VALID_GRANT_TYPES = [
'jwtAssertion',
]

const debug = debugFn('integreat:authenticator:oauth2')

// Create a simple serialization function from a transformer. We're jumping
// through some hoops here, but it makes this behave exactly as form content in
// other parts of Integreat.
Expand Down Expand Up @@ -150,18 +153,22 @@ export default async function authenticate(
body,
headers,
}
debug(`Sending auth request: ${JSON.stringify(request)}`)

let response: Response
try {
response = await fetch(uri, request)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
debug(`Auth attempt failed: ${message}`)
return {
status: 'error',
error: error instanceof Error ? error.message : String(error),
error: message,
}
}

const data = await parseData(response)
debug(`Received auth response: ${JSON.stringify(data)}`)
if (response.ok) {
if (data) {
return {
Expand Down

0 comments on commit 0158af2

Please sign in to comment.