From 78e9c0d2d961bd84a91733c346181a98ee51e6fe Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 11 Jan 2022 11:02:46 +0000 Subject: [PATCH] ui: Ensure the partition is passed through to the request for the SSO auth URL (#11979) * Make sure the mocks reflect the requested partition/namespace * Ensure partition is passed through to the HTTP adapter * Pass AuthMethod object through to TokenSource in order to use Partition * Change up docs and add potential improvements for future * Pass the query partition back onto the response * Make sure the OIDC callback mock returns a Partition * Enable OIDC provider mock overwriting during acceptance testing * Make sure we can enable partitions and SSO post bootup only required ...for now * Wire up oidc provider mocking * Add SSO full auth flow acceptance tests --- .changelog/11979.txt | 4 +++ .../app/components/auth-form/index.hbs | 2 +- .../app/components/token-source/README.mdx | 11 ++++++- .../app/components/token-source/index.hbs | 8 ++--- .../app/serializers/oidc-provider.js | 1 + .../app/services/repository/oidc-provider.js | 3 +- .../consul-ui/mock-api/v1/acl/oidc/callback | 5 ++++ .../mock-api/v1/internal/ui/oidc-auth-methods | 4 +-- .../consul-ui/tests/acceptance/login.feature | 30 +++++++++++++++++++ .../consul-ui/tests/helpers/set-cookies.js | 3 ++ .../consul-ui/tests/helpers/type-to-url.js | 3 ++ ui/packages/consul-ui/tests/steps.js | 9 +++++- .../consul-ui/tests/steps/doubles/http.js | 5 +++- .../consul-ui/tests/steps/doubles/model.js | 8 +++++ 14 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 .changelog/11979.txt diff --git a/.changelog/11979.txt b/.changelog/11979.txt new file mode 100644 index 0000000000..8ef0e855b1 --- /dev/null +++ b/.changelog/11979.txt @@ -0,0 +1,4 @@ +```release-note:bug +ui: Ensure partition query parameter is passed through to all OIDC related API +requests +``` diff --git a/ui/packages/consul-ui/app/components/auth-form/index.hbs b/ui/packages/consul-ui/app/components/auth-form/index.hbs index 3578e467d1..b9ba008f99 100644 --- a/ui/packages/consul-ui/app/components/auth-form/index.hbs +++ b/ui/packages/consul-ui/app/components/auth-form/index.hbs @@ -154,7 +154,7 @@ as |TabState IgnoredGuard IgnoredAction tabDispatch tabState|> @nspace={{or this.value.Namespace @nspace}} @partition={{or this.value.Partition @partition}} @type={{if this.value.Name 'oidc' 'secret'}} - @value={{if this.value.Name this.value.Name this.value}} + @value={{this.value}} @onchange={{queue (action dispatch "RESET") @onsubmit}} @onerror={{queue (action (mut this.error) value="error.errors.firstObject") (action dispatch "ERROR")}} /> diff --git a/ui/packages/consul-ui/app/components/token-source/README.mdx b/ui/packages/consul-ui/app/components/token-source/README.mdx index 8a451f2c83..186cba5d4f 100644 --- a/ui/packages/consul-ui/app/components/token-source/README.mdx +++ b/ui/packages/consul-ui/app/components/token-source/README.mdx @@ -21,6 +21,15 @@ This component **does not store the resulting token**, it only emits it via its `onchange` argument/event handler. Errors are emitted via the `onerror` argument/event handler. +## Potential improvements + +We could decide to remove the `@type` argument and always require an object +passed to `@value` instead of a `String|Object`. Alternatively we could still +allow `String|Object`. Then inside the component we could decide whether to +use the Consul or SSO depending on the shape of the `@value` argument. All in +all this means we can remove the `@type` argument making a slimmer component +API. + ```hbs preview-template
Provide a widget to login with
@@ -75,7 +84,7 @@ argument/event handler. | `nspace` | `String` | | The name of the current namespace | | `partition` | `String` | | The name of the current partition | | `type` | `String` | | `secret` or `oidc`. `secret` is just traditional login, whereas `oidc` uses the users OIDC provider | -| `value` | `String` | | When `type` is `secret` this should be the users secret. When `type` is `oidc` this should be the name of the `AuthMethod` to use for authentication | +| `value` | `String|Object` | | When `type` is `secret` this should be the users secret. When `type` is `oidc` this should be object returned by Consul's AuthMethod HTTP API endpoint | | `onchange` | `Function` | | The action to fire when the data changes. Emits an Event-like object with a `data` property containing the jwt data, in this case the autorizationCode and the status | | `onerror` | `Function` | | The action to fire when an error occurs. Emits ErrorEvent object with an `error` property containing the Error. | diff --git a/ui/packages/consul-ui/app/components/token-source/index.hbs b/ui/packages/consul-ui/app/components/token-source/index.hbs index 94186be1ba..962fc7774a 100644 --- a/ui/packages/consul-ui/app/components/token-source/index.hbs +++ b/ui/packages/consul-ui/app/components/token-source/index.hbs @@ -7,10 +7,10 @@ as |State Guard Action dispatch state|> @cond={{this.isSecret}} /> {{#let - (uri '/${partition}/{$nspace}/${dc}' + (uri '/${partition}/${nspace}/${dc}' (hash - partition=@partition - nspace=@nspace + partition=(or @value.Partition @partition) + nspace=(or @value.Namespace @nspace) dc=@dc ) ) @@ -30,7 +30,7 @@ as |State Guard Action dispatch state|>