Skip to content
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

Support for multiple client_id and client_secret #9312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 42 additions & 2 deletions dev-helpers/dev-helper-initializer.js
Expand Up @@ -4,7 +4,36 @@ window.onload = function() {
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
// Build a system
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
spec: {
swagger: '2.0',
info: {
title: "test",
version: '1.0.0'
},
paths: {
'/foo': {
get: {
responses: {
'200': {
description: 'OK'
}
}
}
}
},
"securityDefinitions": {
"test_auth_implicit": {
"type": "oauth2",
"authorizationUrl": "https://oauth2provider.com/oauth/authorize",
"flow": "implicit"
},
"test_auth_password": {
"type": "oauth2",
"authorizationUrl": "https://oauth2provider.com/oauth/authorize",
"flow": "password"
}
}
},
dom_id: "#swagger-ui",
presets: [
SwaggerUIBundle.presets.apis,
Expand All @@ -28,6 +57,17 @@ window.onload = function() {
scopes: "openid profile email phone address",
additionalQueryStringParams: {},
useBasicAuthenticationWithAccessCodeGrant: false,
usePkceWithAuthorizationCodeGrant: false
usePkceWithAuthorizationCodeGrant: false,
oauth2FlowOverwrites: [
["implicit", {
clientId: "client_id_123",
clientSecret: "secret123"
}],
["password", {
clientId: "client_id_456",
clientSecret: "secret456"
}]

],
})
}
10 changes: 7 additions & 3 deletions src/core/components/auth/oauth2.jsx
Expand Up @@ -30,6 +30,7 @@ export default class Oauth2 extends React.Component {
if (typeof scopes === "string") {
scopes = scopes.split(authConfigs.scopeSeparator || " ")
}
let oauth2FlowOverwrites = auth && auth.get("oauth2FlowOverwrites") || authConfigs.oauth2FlowOverwrites || ""

this.state = {
appName: authConfigs.appName,
Expand All @@ -38,6 +39,7 @@ export default class Oauth2 extends React.Component {
scopes: scopes,
clientId: clientId,
clientSecret: clientSecret,
oauth2FlowOverwrites: oauth2FlowOverwrites && new Map(oauth2FlowOverwrites),
username: username,
password: "",
passwordType: passwordType
Expand Down Expand Up @@ -141,6 +143,8 @@ export default class Oauth2 extends React.Component {
let errors = errSelectors.allErrors().filter( err => err.get("authId") === name)
let isValid = !errors.filter( err => err.get("source") === "validation").size
let description = schema.get("description")
let clientId = (this.state.oauth2FlowOverwrites && this.state.oauth2FlowOverwrites.get(flow) && this.state.oauth2FlowOverwrites.get(flow).clientId) || this.state.clientId
let clientSecret = (this.state.oauth2FlowOverwrites && this.state.oauth2FlowOverwrites.get(flow) && this.state.oauth2FlowOverwrites.get(flow).clientSecret) || this.state.clientSecret

return (
<div>
Expand Down Expand Up @@ -195,15 +199,15 @@ export default class Oauth2 extends React.Component {
}
{
( flow === AUTH_FLOW_APPLICATION || flow === AUTH_FLOW_IMPLICIT || flow === AUTH_FLOW_ACCESS_CODE || flow === AUTH_FLOW_PASSWORD ) &&
( !isAuthorized || isAuthorized && this.state.clientId) && <Row>
( !isAuthorized || isAuthorized && clientId) && <Row>
<label htmlFor="client_id">client_id:</label>
{
isAuthorized ? <code> ****** </code>
: <Col tablet={10} desktop={10}>
<InitializedInput id="client_id"
type="text"
required={ flow === AUTH_FLOW_PASSWORD }
initialValue={ this.state.clientId }
initialValue={ clientId }
data-name="clientId"
onChange={ this.onInputChange }/>
</Col>
Expand All @@ -218,7 +222,7 @@ export default class Oauth2 extends React.Component {
isAuthorized ? <code> ****** </code>
: <Col tablet={10} desktop={10}>
<InitializedInput id="client_secret"
initialValue={ this.state.clientSecret }
initialValue={ clientSecret }
type="password"
data-name="clientSecret"
onChange={ this.onInputChange }/>
Expand Down