Skip to content

Commit

Permalink
refactor: remove the deprecated OIDCContext.prototype.bearer method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The deprecated `OIDCContext.prototype.bearer` method
is removed.
  • Loading branch information
panva committed Mar 10, 2020
1 parent d045a8a commit 52000d5
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions lib/helpers/oidc_context.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const events = require('events');
const url = require('url');
const { deprecate } = require('util');

const debug = require('debug')('oidc-provider:bearer');
const { JWT, JWK } = require('jose');
Expand Down Expand Up @@ -338,55 +337,5 @@ module.exports = function getContext(provider) {
}
}

Object.defineProperty(OIDCContext.prototype, 'bearer', {
get: deprecate(/* istanbul ignore next */ function getBearer() {
if ('bearer' in instance(this)) {
return instance(this).bearer;
}
const { ctx } = this;
const mechanisms = omitBy({
body: get(ctx.oidc, 'body.access_token'),
header: ctx.headers.authorization,
query: ctx.query.access_token,
}, (x) => typeof x === 'undefined');

debug('uid=%s received bearer via %o', this.uid, mechanisms);

let mechanism;
let length;
let bearer;

try {
({ 0: [mechanism, bearer], length } = Object.entries(mechanisms));
} catch (err) {}

if (!length) {
throw new InvalidRequest('no bearer auth mechanism provided');
}

if (length > 1) {
throw new InvalidRequest('bearer token must only be provided using one mechanism');
}

if (mechanism === 'header') {
const header = bearer;
const { 0: scheme, 1: value, length: parts } = header.split(' ');

if (parts !== 2 || scheme.toLowerCase() !== 'bearer') {
throw new InvalidRequest('invalid authorization header value format');
}

bearer = value;
}

if (!bearer) {
throw new InvalidRequest('no bearer token provided');
}

instance(this).bearer = bearer;
return bearer;
}, 'ctx.oidc.bearer is deprecated, use ctx.oidc.getAccessToken() instead'),
});

return OIDCContext;
};

0 comments on commit 52000d5

Please sign in to comment.