-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Resource Indicators for OAuth 2.0 - draft 00 implementation
Based on https://tools.ietf.org/html/draft-ietf-oauth-resource-indicators-00 this feature enables the client and authorization server to more explicitly to communicate about the protected resource(s) to be accessed. Enabling this feature adds the `resource` parameter to authorization and token endpoint whitelists, validates the value(s) as per the draft (only absolute uris, no query, no fragment). Simply enabling the feature will not push these additional resources as audiences to your tokens, to do that you must use the `audiences` helper function. See the docs section for a complete example combining the feature, audiences and dynamic access token ttl.
- Loading branch information
Showing
14 changed files
with
726 additions
and
9 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
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,38 @@ | ||
const { URL } = require('url'); | ||
|
||
const instance = require('../helpers/weak_cache'); | ||
const { InvalidResource } = require('../helpers/errors'); | ||
|
||
module.exports = function getCheckResource(provider) { | ||
return function checkResource({ oidc: { params } }, next) { | ||
if (!instance(provider).configuration('features.resourceIndicators') || params.resource === undefined) { | ||
return next(); | ||
} | ||
|
||
let requested = params.resource; | ||
if (!Array.isArray(requested)) { | ||
requested = [requested]; | ||
} | ||
|
||
requested.forEach((resource) => { | ||
let href; | ||
try { | ||
({ href } = new URL(resource)); // eslint-disable-line no-new | ||
} catch (err) { | ||
throw new InvalidResource('resource must be an absolute URI'); | ||
} | ||
|
||
// NOTE: we don't check for new URL() => search of hash because of an edge case | ||
// new URL('https://example.com?#') => they're empty, seems like an inconsistent validation | ||
if (href.includes('#')) { | ||
throw new InvalidResource('resource must not contain a fragment component'); | ||
} | ||
|
||
if (href.includes('?')) { | ||
throw new InvalidResource('resource must not contain a query component'); | ||
} | ||
}); | ||
|
||
return next(); | ||
}; | ||
}; |
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
Oops, something went wrong.