-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'admin-jwt' into 'master'
Admin jwt See merge request special/change-logs-producer!3
- Loading branch information
Showing
11 changed files
with
536 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use strict" | ||
/** | ||
* This implements a middleware which just checks the Authorization header | ||
* for a bearer token and validates this at the OIDC /userinfo endpoint | ||
* If authentication fails we just call next('route') to let the app default | ||
* behaviour handle it | ||
* | ||
* It's a quick hack to support service accounts | ||
*/ | ||
const request = require("superagent") | ||
const {UNAUTHORIZED} = require("http-status-codes") | ||
const endpoint = process.env.AUTH_USERINFO_ENDPOINT || "http://localhost:8080/auth/realms/master/protocol/openid-connect/userinfo" | ||
|
||
function jwtAuth (req, res, next) { | ||
// TODO: to be spec compliant a token can also be passed into the body or | ||
// as a query parameter, but we're only supporting the Authorization header | ||
// at the moment (it is a hack remember) | ||
// see: https://github.com/jaredhanson/passport-http-bearer/blob/master/lib/strategy.js | ||
if (!req.headers || !req.headers.authorization) return next("route") | ||
const parts = req.headers.authorization.split(" ") | ||
if (parts.length !== 2) return next("route") | ||
const [scheme, token] = parts | ||
if (!/^Bearer$/i.test(scheme)) return next("route") | ||
req.log.debug({token}, "Parsed access_token") | ||
|
||
// At this stage we have a token, let's verify it | ||
request | ||
.get(endpoint) | ||
.set("Authorization", `Bearer ${token}`) | ||
.set("Accept", "application/json") | ||
.end((err) => { | ||
if (err) { | ||
req.log.warn({error: err}, "Failed to authorize access token") | ||
return res.status(err.status || UNAUTHORIZED).send() | ||
} | ||
return next() | ||
}) | ||
} | ||
|
||
module.exports = jwtAuth |
Oops, something went wrong.