improvement: oauth "scopes" improvements (#6037)

* improvement: oauth "scopes" init parameter

* improvement: add "select all" and "select none" to oauth scopes popup
This commit is contained in:
Matthew Morrissette
2020-06-10 11:27:54 -07:00
committed by GitHub
parent 4497387d62
commit 275c8f2ccf
9 changed files with 62 additions and 4 deletions

View File

@@ -25,12 +25,16 @@ export default class Oauth2 extends React.Component {
let clientId = auth && auth.get("clientId") || authConfigs.clientId || ""
let clientSecret = auth && auth.get("clientSecret") || authConfigs.clientSecret || ""
let passwordType = auth && auth.get("passwordType") || "basic"
let scopes = auth && auth.get("scopes") || authConfigs.scopes || []
if (typeof scopes === "string") {
scopes = scopes.split(authConfigs.scopeSeparator || " ")
}
this.state = {
appName: authConfigs.appName,
name: name,
schema: schema,
scopes: [],
scopes: scopes,
clientId: clientId,
clientSecret: clientSecret,
username: username,
@@ -77,6 +81,16 @@ export default class Oauth2 extends React.Component {
this.setState(state)
}
selectScopes =(e) => {
if (e.target.dataset.all) {
this.setState({
scopes: Array.from((this.props.schema.get("allowedScopes") || this.props.schema.get("scopes")).keys())
})
} else {
this.setState({ scopes: [] })
}
}
logout =(e) => {
e.preventDefault()
let { authActions, errActions, name } = this.props
@@ -201,7 +215,11 @@ export default class Oauth2 extends React.Component {
{
!isAuthorized && scopes && scopes.size ? <div className="scopes">
<h2>Scopes:</h2>
<h2>
Scopes:
<a onClick={this.selectScopes} data-all={true}>select all</a>
<a onClick={this.selectScopes}>select none</a>
</h2>
{ scopes.map((description, name) => {
return (
<Row key={ name }>
@@ -209,6 +227,7 @@ export default class Oauth2 extends React.Component {
<Input data-value={ name }
id={`${name}-${flow}-checkbox-${this.state.name}`}
disabled={ isAuthorized }
checked={ this.state.scopes.includes(name) }
type="checkbox"
onChange={ this.onScopeChange }/>
<label htmlFor={`${name}-${flow}-checkbox-${this.state.name}`}>