diff --git a/dev-helpers/index.html b/dev-helpers/index.html index ca4ddb98196..f9161c82b62 100644 --- a/dev-helpers/index.html +++ b/dev-helpers/index.html @@ -62,6 +62,7 @@ realm: "your-realms", appName: "your-app-name", scopeSeparator: " ", + scopes: "openid profile email phone address", additionalQueryStringParams: {}, usePkceWithAuthorizationCodeGrant: false }) diff --git a/docker/configurator/oauth.js b/docker/configurator/oauth.js index 75d15e8eb0a..46c174412df 100644 --- a/docker/configurator/oauth.js +++ b/docker/configurator/oauth.js @@ -23,6 +23,10 @@ const oauthBlockSchema = { type: "string", name: "scopeSeparator" }, + OAUTH_SCOPES: { + type: "string", + name: "scopes" + }, OAUTH_ADDITIONAL_PARAMS: { type: "object", name: "additionalQueryStringParams" @@ -44,4 +48,4 @@ ${indent(translatorResult, 2)} } return `` -} \ No newline at end of file +} diff --git a/docs/usage/oauth2.md b/docs/usage/oauth2.md index 8bd8fbc60d6..5e5d96572b3 100644 --- a/docs/usage/oauth2.md +++ b/docs/usage/oauth2.md @@ -8,6 +8,7 @@ clientSecret | `OAUTH_CLIENT_SECRET` | **🚨 Never use this parameter in your p realm | `OAUTH_REALM` |realm query parameter (for oauth1) added to `authorizationUrl` and `tokenUrl`. MUST be a string appName | `OAUTH_APP_NAME` |application name, displayed in authorization popup. MUST be a string scopeSeparator | `OAUTH_SCOPE_SEPARATOR` |scope separator for passing scopes, encoded before calling, default value is a space (encoded value `%20`). MUST be a string +scopes | `OAUTH_SCOPES` |string array or scope separator (i.e. space) separated string of initially selected oauth scopes, default is empty array additionalQueryStringParams | `OAUTH_ADDITIONAL_PARAMS` |Additional query parameters added to `authorizationUrl` and `tokenUrl`. MUST be an object useBasicAuthenticationWithAccessCodeGrant | _Unavailable_ |Only activated for the `accessCode` flow. During the `authorization_code` request to the `tokenUrl`, pass the [Client Password](https://tools.ietf.org/html/rfc6749#section-2.3.1) using the HTTP Basic Authentication scheme (`Authorization` header with `Basic base64encode(client_id + client_secret)`). The default is `false` usePkceWithAuthorizationCodeGrant | `OAUTH_USE_PKCE` | Only applies to `authorizatonCode` flows. [Proof Key for Code Exchange](https://tools.ietf.org/html/rfc7636) brings enhanced security for OAuth public clients. The default is `false` @@ -22,6 +23,7 @@ ui.initOAuth({ realm: "your-realms", appName: "your-app-name", scopeSeparator: " ", + scopes: "openid profile", additionalQueryStringParams: {test: "hello"}, usePkceWithAuthorizationCodeGrant: true }) diff --git a/src/core/components/auth/oauth2.jsx b/src/core/components/auth/oauth2.jsx index 1d3c95db3a7..966de0f8f4b 100644 --- a/src/core/components/auth/oauth2.jsx +++ b/src/core/components/auth/oauth2.jsx @@ -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 ?
-

Scopes:

+

+ Scopes: + select all + select none +

{ scopes.map((description, name) => { return ( @@ -209,6 +227,7 @@ export default class Oauth2 extends React.Component {