add configuration of auth: scope separator, client id, client secret, app name, reaml, additionalQueryParams
This commit is contained in:
@@ -21,14 +21,16 @@ export default class Oauth2 extends React.Component {
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
let { name, schema, authorized } = this.props
|
||||
let { name, schema, authorized, authSelectors } = this.props
|
||||
let auth = authorized && authorized.get(name)
|
||||
let authConfigs = authSelectors.getConfigs() || {}
|
||||
let username = auth && auth.get("username") || ""
|
||||
let clientId = auth && auth.get("clientId") || ""
|
||||
let clientSecret = auth && auth.get("clientSecret") || ""
|
||||
let clientId = auth && auth.get("clientId") || authConfigs.clientId || ""
|
||||
let clientSecret = auth && auth.get("clientSecret") || authConfigs.clientSecret || ""
|
||||
let passwordType = auth && auth.get("passwordType") || "basic"
|
||||
|
||||
this.state = {
|
||||
appName: authConfigs.appName,
|
||||
name: name,
|
||||
schema: schema,
|
||||
scopes: [],
|
||||
@@ -41,11 +43,12 @@ export default class Oauth2 extends React.Component {
|
||||
}
|
||||
|
||||
authorize =() => {
|
||||
let { authActions, errActions, getConfigs } = this.props
|
||||
let { authActions, errActions, getConfigs, authSelectors } = this.props
|
||||
let configs = getConfigs()
|
||||
let authConfigs = authSelectors.getConfigs()
|
||||
|
||||
errActions.clear({authId: name,type: "auth", source: "auth"})
|
||||
oauth2Authorize(this.state, authActions, errActions, configs)
|
||||
oauth2Authorize({auth: this.state, authActions, errActions, configs, authConfigs })
|
||||
}
|
||||
|
||||
onScopeChange =(e) => {
|
||||
@@ -98,6 +101,7 @@ export default class Oauth2 extends React.Component {
|
||||
return (
|
||||
<div>
|
||||
<h4>OAuth2.0 <JumpToPath path={[ "securityDefinitions", name ]} /></h4>
|
||||
{ !this.state.appName ? null : <h5>Application: { this.state.appName } </h5> }
|
||||
<Markdown options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
||||
source={ schema.get("description") } />
|
||||
|
||||
@@ -153,7 +157,11 @@ export default class Oauth2 extends React.Component {
|
||||
{
|
||||
isAuthorized ? <code> ****** </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<input id="client_id" type="text" required={ flow === PASSWORD } data-name="clientId"
|
||||
<input id="client_id"
|
||||
type="text"
|
||||
required={ flow === PASSWORD }
|
||||
value={ this.state.clientId }
|
||||
data-name="clientId"
|
||||
onChange={ this.onInputChange }/>
|
||||
</Col>
|
||||
}
|
||||
@@ -166,7 +174,10 @@ export default class Oauth2 extends React.Component {
|
||||
{
|
||||
isAuthorized ? <code> ****** </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<input id="client_secret" type="text" data-name="clientSecret"
|
||||
<input id="client_secret"
|
||||
value={ this.state.clientSecret }
|
||||
type="text"
|
||||
data-name="clientSecret"
|
||||
onChange={ this.onInputChange }/>
|
||||
</Col>
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ module.exports = function SwaggerUI(opts) {
|
||||
var system = store.getSystem()
|
||||
let queryConfig = parseSeach()
|
||||
|
||||
system.initOAuth = system.authActions.configureAuth
|
||||
|
||||
const downloadSpec = (fetchedConfig) => {
|
||||
if(typeof constructorConfig !== "object") {
|
||||
return system
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import win from "core/window"
|
||||
import { btoa } from "core/utils"
|
||||
|
||||
export default function authorize ( auth, authActions, errActions, configs ) {
|
||||
export default function authorize ( { auth, authActions, errActions, configs, authConfigs={} } ) {
|
||||
let { schema, scopes, name, clientId } = auth
|
||||
|
||||
let { additionalQueryStringParams } = authConfigs
|
||||
let redirectUrl = configs.oauth2RedirectUrl
|
||||
let scopeSeparator = " "
|
||||
let scopeSeparator = authConfigs.scopeSeparator || " "
|
||||
let state = btoa(new Date())
|
||||
let flow = schema.get("flow")
|
||||
let url
|
||||
@@ -36,10 +37,15 @@ export default function authorize ( auth, authActions, errActions, configs ) {
|
||||
}
|
||||
|
||||
url += "&redirect_uri=" + encodeURIComponent(redirectUrl)
|
||||
+ "&realm=" + encodeURIComponent(authConfigs.realm);
|
||||
+ "&scope=" + encodeURIComponent(scopes.join(scopeSeparator))
|
||||
+ "&state=" + encodeURIComponent(state)
|
||||
+ "&client_id=" + encodeURIComponent(clientId)
|
||||
|
||||
for (let key in additionalQueryStringParams) {
|
||||
url += "&" + key + "=" + encodeURIComponent(additionalQueryStringParams[key])
|
||||
}
|
||||
|
||||
// pass action authorizeOauth2 and authentication data through window
|
||||
// to authorize with oauth2
|
||||
win.swaggerUIRedirectOauth2 = {
|
||||
|
||||
@@ -7,6 +7,7 @@ export const LOGOUT = "logout"
|
||||
export const PRE_AUTHORIZE_OAUTH2 = "pre_authorize_oauth2"
|
||||
export const AUTHORIZE_OAUTH2 = "authorize_oauth2"
|
||||
export const VALIDATE = "validate"
|
||||
export const CONFIGURE_AUTH = "configure_auth"
|
||||
|
||||
const scopeSeparator = " "
|
||||
|
||||
@@ -117,8 +118,14 @@ export const authorizeAccessCode = ( auth ) => ( { authActions } ) => {
|
||||
|
||||
}
|
||||
|
||||
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions } ) => {
|
||||
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => {
|
||||
let { body, query={}, headers={}, name, url, auth } = data
|
||||
let { additionalQueryStringParams } = authSelectors.getConfigs() || {}
|
||||
let fetchUrl = url
|
||||
|
||||
for (let key in additionalQueryStringParams) {
|
||||
url += "&" + key + "=" + encodeURIComponent(additionalQueryStringParams[key])
|
||||
}
|
||||
|
||||
let _headers = Object.assign({
|
||||
"Accept":"application/json, text/plain, */*",
|
||||
@@ -127,7 +134,7 @@ export const authorizeRequest = ( data ) => ( { fn, authActions, errActions } )
|
||||
}, headers)
|
||||
|
||||
fn.fetch({
|
||||
url: url,
|
||||
url: fetchUrl,
|
||||
method: "post",
|
||||
headers: _headers,
|
||||
query: query,
|
||||
@@ -169,3 +176,10 @@ export const authorizeRequest = ( data ) => ( { fn, authActions, errActions } )
|
||||
message: err.message
|
||||
} ) })
|
||||
}
|
||||
|
||||
export function configureAuth(payload) {
|
||||
return {
|
||||
type: CONFIGURE_AUTH,
|
||||
payload: payload
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import {
|
||||
SHOW_AUTH_POPUP,
|
||||
AUTHORIZE,
|
||||
AUTHORIZE_OAUTH2,
|
||||
LOGOUT
|
||||
LOGOUT,
|
||||
CONFIGURE_AUTH
|
||||
} from "./actions"
|
||||
|
||||
export default {
|
||||
@@ -57,5 +58,9 @@ export default {
|
||||
})
|
||||
|
||||
return state.set("authorized", result)
|
||||
},
|
||||
|
||||
[CONFIGURE_AUTH]: (state, { payload } ) =>{
|
||||
return state.set("configs", payload)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,3 +79,8 @@ export const isAuthorized = ( state, securities ) =>( { authSelectors } ) => {
|
||||
}).indexOf(false) === -1
|
||||
}).length
|
||||
}
|
||||
|
||||
export const getConfigs = createSelector(
|
||||
state,
|
||||
auth => auth.get( "configs" )
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user