Skip to content

Commit

Permalink
fix hook auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuyanh committed Jul 10, 2023
1 parent 922dc67 commit 703039a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gcp-cloudrun-merge-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
push:
branches:
- develop
- feature/post-update-web
- fix-hook-auth

name: Build and Deploy to Cloud Run on merge to branch 'develop'
env:
Expand Down
17 changes: 13 additions & 4 deletions src/handler/hook/hook_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import { loadConfig } from '../../config/config'

export const hookMiddleware = (req: Request, res: Response, next: NextFunction) => {
const conf = loadConfig()
const auth = req.headers['authorization'].split(' ')[1]
const auth = req.headers['authorization']
console.log(`auth: ${auth}`)

if (auth == null) return res.sendStatus(401)
if (auth.split(' ')[0] === 'Bearer') res.sendStatus(403)

const parts = auth.split(' ')
if (parts.length !== 2 || parts[0] !== 'Bearer') {
console.error(`invalid auth header: ${parts}`)
res.sendStatus(403)
}
const token = parts[1]
console.log(`token: ${token}`)

try {
const decoded = jwt.verify(auth, conf.accessToken)
const decoded = jwt.verify(token, conf.accessToken)
next()
} catch (err) {
console.log(err)
console.error(`jwt verify: ${err}`)
return res.sendStatus(403)
}
}

0 comments on commit 703039a

Please sign in to comment.