-
Notifications
You must be signed in to change notification settings - Fork 228
feat: add support for OAuth clientCredential and password flows in Respect core #2824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshit078
wants to merge
23
commits into
Redocly:main
Choose a base branch
from
harshit078:Add-support-for-clientCredential
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
88ef47b
feat: added OAuth2 support and enhance security parameter handling
harshit078 02abd75
Merge branch 'main' into Add-support-for-clientCredential
harshit078 590d9b8
feat: extended OAuth2 support by adding token exchange
harshit078 b834cf2
feat: added Oath2 validation tests
harshit078 789afed
feat: added security validation async3
harshit078 c59d0a4
Merge branch 'main' into Add-support-for-clientCredential
harshit078 978d836
feat: added OAuth2 token and password flow
harshit078 ef3b37c
feat: added test for oauth2
harshit078 8528b1f
Merge branch 'main' into Add-support-for-clientCredential
harshit078 9978d3b
feat: added changeset
harshit078 9de2521
fix: failing vale failing test
harshit078 e06b3a0
fix: comments addressed by cursor
harshit078 a8fc9a8
Merge branch 'main' into Add-support-for-clientCredential
harshit078 0dfb96d
fix: failing lint test
harshit078 cda6f48
fix: comment left by cursor
harshit078 9ef677b
fix: failing lint test
harshit078 637545a
fix: failing lint test
harshit078 25a0c58
Merge branch 'main' into Add-support-for-clientCredential
harshit078 3978e59
fix: address cursor comments
harshit078 120e465
fix: addrress cursor bot comment
harshit078 a160588
Merge branch 'main' into Add-support-for-clientCredential
harshit078 a98fd8c
fix: addrress cursor bot comment
harshit078 912da7e
Merge branch 'main' into Add-support-for-clientCredential
harshit078 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
| --- | ||
| '@redocly/respect-core': minor | ||
| '@redocly/openapi-core': minor | ||
| '@redocly/cli': minor | ||
| --- | ||
|
|
||
| Added OAuth2 token exchange for `x-security` schemes with the `password` and `clientCredentials` flows. Respect fetches the access token from `tokenUrl` and apply `Authorization: Bearer` to the request, which allows to manually obtain a `accessToken`. The `x-security-scheme-required-values` rule now validates the credentials required by the declared flow. Pre-fetched `accessToken` values continue to work. |
This file contains hidden or 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 hidden or 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,84 @@ | ||
| import { isRef } from '../../ref-utils.js'; | ||
| import type { Location } from '../../ref-utils.js'; | ||
| import type { Async3Rule } from '../../visitors.js'; | ||
| import type { UserContext } from '../../walk.js'; | ||
|
|
||
| type SecurityReference = { | ||
| location: Location; | ||
| name: string; | ||
| resolvedAbsolutePointer?: string; | ||
| resolved: boolean; | ||
| }; | ||
|
|
||
| export const SecurityDefined: Async3Rule = () => { | ||
| const definedSchemeAbsolutePointers = new Set<string>(); | ||
| const references: SecurityReference[] = []; | ||
| const operationsWithoutSecurity: Location[] = []; | ||
| let eachOperationHasSecurity = true; | ||
|
|
||
| return { | ||
| Root: { | ||
| leave(_root: unknown, { report }: UserContext) { | ||
| for (const reference of references) { | ||
| if ( | ||
| reference.resolved && | ||
| reference.resolvedAbsolutePointer && | ||
| definedSchemeAbsolutePointers.has(reference.resolvedAbsolutePointer) | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| if (!reference.resolved) { | ||
| report({ | ||
| message: `There is no \`${reference.name}\` security scheme defined.`, | ||
| location: reference.location.key(), | ||
| }); | ||
| } else { | ||
| report({ | ||
| message: `Security scheme \`$ref\` must point to \`#/components/securitySchemes\`.`, | ||
| location: reference.location.key(), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (!eachOperationHasSecurity) { | ||
| for (const operationLocation of operationsWithoutSecurity) { | ||
| report({ | ||
| message: `Every operation should have security defined on it.`, | ||
| location: operationLocation.key(), | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| NamedSecuritySchemes: { | ||
| SecurityScheme(_scheme: unknown, { location }: UserContext) { | ||
| definedSchemeAbsolutePointers.add(location.absolutePointer.toString()); | ||
| }, | ||
| }, | ||
| SecuritySchemeList: { | ||
| enter(list: unknown[] | undefined, { location, resolve }: UserContext) { | ||
| if (!list) return; | ||
| for (let i = 0; i < list.length; i++) { | ||
| const item = list[i]; | ||
| if (!isRef(item)) continue; | ||
| const itemLocation = location.child([i]); | ||
| const resolved = resolve(item); | ||
| const name = item.$ref.split('/').pop() ?? item.$ref; | ||
| references.push({ | ||
| location: itemLocation, | ||
| name, | ||
| resolvedAbsolutePointer: resolved.location?.absolutePointer.toString(), | ||
| resolved: resolved.node !== undefined, | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| Operation(operation: { security?: unknown }, { location }: UserContext) { | ||
| if (!operation?.security) { | ||
| eachOperationHasSecurity = false; | ||
| operationsWithoutSecurity.push(location); | ||
| } | ||
| }, | ||
| }; | ||
| }; | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.