-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3780 from swagger-api/ft/oas3-authorization
OAS 3.0 Authorization
- Loading branch information
Showing
16 changed files
with
435 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
import ImPropTypes from "react-immutable-proptypes" | ||
|
||
export default class Auths extends React.Component { | ||
static propTypes = { | ||
schema: ImPropTypes.orderedMap.isRequired, | ||
name: PropTypes.string.isRequired, | ||
onAuthChange: PropTypes.func.isRequired, | ||
authorized: ImPropTypes.orderedMap.isRequired | ||
} | ||
|
||
render() { | ||
let { | ||
schema, | ||
name, | ||
getComponent, | ||
onAuthChange, | ||
authorized, | ||
errSelectors | ||
} = this.props | ||
const ApiKeyAuth = getComponent("apiKeyAuth") | ||
const BasicAuth = getComponent("basicAuth") | ||
|
||
let authEl | ||
|
||
const type = schema.get("type") | ||
|
||
switch(type) { | ||
case "apiKey": authEl = <ApiKeyAuth key={ name } | ||
schema={ schema } | ||
name={ name } | ||
errSelectors={ errSelectors } | ||
authorized={ authorized } | ||
getComponent={ getComponent } | ||
onChange={ onAuthChange } /> | ||
break | ||
case "basic": authEl = <BasicAuth key={ name } | ||
schema={ schema } | ||
name={ name } | ||
errSelectors={ errSelectors } | ||
authorized={ authorized } | ||
getComponent={ getComponent } | ||
onChange={ onAuthChange } /> | ||
break | ||
default: authEl = <div key={ name }>Unknown security definition type { type }</div> | ||
} | ||
|
||
return (<div key={`${name}-jump`}> | ||
{ authEl } | ||
</div>) | ||
} | ||
|
||
static propTypes = { | ||
errSelectors: PropTypes.object.isRequired, | ||
getComponent: PropTypes.func.isRequired, | ||
authSelectors: PropTypes.object.isRequired, | ||
specSelectors: PropTypes.object.isRequired, | ||
authActions: PropTypes.object.isRequired, | ||
definitions: ImPropTypes.iterable.isRequired | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,60 @@ | ||
import { createSelector } from "reselect" | ||
import { List } from "immutable" | ||
import { List, Map, fromJS } from "immutable" | ||
import { isOAS3 as isOAS3Helper } from "../helpers" | ||
|
||
|
||
// Helpers | ||
|
||
const state = state => state | ||
|
||
function onlyOAS3(selector) { | ||
return (ori, system) => (state, ...args) => { | ||
const spec = system.getSystem().specSelectors.specJson() | ||
if(isOAS3Helper(spec)) { | ||
return selector(...args) | ||
return selector(system, ...args) | ||
} else { | ||
return ori(...args) | ||
} | ||
} | ||
} | ||
|
||
const nullSelector = createSelector(() => null) | ||
export const definitionsToAuthorize = onlyOAS3(createSelector( | ||
state, | ||
({ specSelectors }) => { | ||
// Coerce our OpenAPI 3.0 definitions into monoflow definitions | ||
// that look like Swagger2 definitions. | ||
let definitions = specSelectors.securityDefinitions() | ||
let list = List() | ||
|
||
definitions.entrySeq().forEach( ([ defName, definition ]) => { | ||
const type = definition.get("type") | ||
|
||
const OAS3NullSelector = onlyOAS3(nullSelector) | ||
if(type === "oauth2") { | ||
definition.get("flows").entrySeq().forEach(([flowKey, flowVal]) => { | ||
let translatedDef = fromJS({ | ||
flow: flowKey, | ||
authorizationUrl: flowVal.get("authorizationUrl"), | ||
tokenUrl: flowVal.get("tokenUrl"), | ||
scopes: flowVal.get("scopes"), | ||
type: definition.get("type") | ||
}) | ||
|
||
// Hasta la vista, authorization! | ||
export const shownDefinitions = OAS3NullSelector | ||
export const definitionsToAuthorize = OAS3NullSelector | ||
export const getDefinitionsByNames = OAS3NullSelector | ||
export const authorized = onlyOAS3(() => List()) | ||
export const isAuthorized = OAS3NullSelector | ||
export const getConfigs = OAS3NullSelector | ||
list = list.push(new Map({ | ||
[defName]: translatedDef.filter((v) => { | ||
// filter out unset values, sometimes `authorizationUrl` | ||
// and `tokenUrl` come out as `undefined` in the data | ||
return v !== undefined | ||
}) | ||
})) | ||
}) | ||
} | ||
if(type === "http" || type === "apiKey") { | ||
list = list.push(new Map({ | ||
[defName]: definition | ||
})) | ||
} | ||
}) | ||
|
||
return list | ||
} | ||
)) |
Oops, something went wrong.