feat: add token page - #273
Open
olblak wants to merge 2 commits into
Open
Conversation
Udash now issues its own long-lived API tokens, because an identity provider
access token always expires while an unattended CI pipeline needs a credential it
can keep. The frontend is where a user creates one.
This also closes a gap that already existed: `GetStartedSteps.vue` told users to
`export UPDATECLI_UDASH_ACCESS_TOKEN="your_token_here"` with **no way to obtain
one**.
Nothing here changes how the SPA authenticates. It already uses `oidc-client-ts`
with generic `OAUTH_*` runtime config, so it is provider-agnostic as it stands.
Follows the house style confirmed from the existing components: Options API with
`setup()` only bridging composables (there is no `<script setup>` anywhere),
Vuetify 4, MDI icons.
- `v-data-table-virtual` listing name, scopes, created, last used, expires —
modelled on `src/components/pipeline/reports.vue`, including its empty-state
convention (96px grey icon + `text-h5` heading).
- Create dialog with a name field and scope checkboxes. This is **new ground**:
the codebase had no POST-from-a-form precedent, only POST-search.
- One-time reveal in a dismissible `v-alert`, reusing the clipboard pattern from
`GetStartedSteps.vue` (`copiedKey` + 1.5s `mdi-check` swap). It does not
auto-dismiss, because the token cannot be recovered afterwards.
- Revoke confirmation dialog.
- The **New token** button is hidden unless `GET /whoami` reports `publisher` or
`admin`. This is UX only — `POST /api/tokens` is what actually enforces it.
All calls go through the existing `apiFetch(path, { method, body })` in
`src/composables/api.js`, which already attaches the bearer. No new HTTP layer.
`/profile/tokens` → `TokensView`, with `beforeEnter: authGuard`.
Registered **only in the `isAuthEnabled` branch**, exactly like `/profile`. The
routes array is duplicated across both branches of an `if`, and API tokens are
meaningless on an open instance.
`<v-list-item prepend-icon="mdi-key" title="Tokens" to="/profile/tokens">` in the
account menu, between Profile and Logout.
A line under the Authenticate step linking to `/profile/tokens`, shown only when
auth is enabled.
Two things worth knowing if you touch this:
- The link is a `<router-link>` in the template, **not** an `<a href>` inside the
step's `v-html` description. The app uses `createWebHistory`, not hash routing,
so a raw anchor would trigger a full page reload and ignore `getAppBasePath()`.
- `isAuthEnabled` is a module-level constant, so it had to be exposed through
`computed` for the template to see it under the Options API.
Also updated the sample env var from `your_token_here` to `udash_pat_...`, and
noted that `udash login` prompts for the token or takes `--token`.
Signed-off-by: Olivier Vernin <olivier@vernin.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Udash now issues its own long-lived API tokens, because an identity provider access token always expires while an unattended CI pipeline needs a credential it can keep. The frontend is where a user creates one.
This also closes a gap that already existed:
GetStartedSteps.vuetold users toexport UPDATECLI_UDASH_ACCESS_TOKEN="your_token_here"with no way to obtain one.Nothing here changes how the SPA authenticates. It already uses
oidc-client-tswith genericOAUTH_*runtime config, so it is provider-agnostic as it stands.Follows the house style confirmed from the existing components: Options API with
setup()only bridging composables (there is no<script setup>anywhere), Vuetify 4, MDI icons.t
v-data-table-virtuallisting name, scopes, created, last used, expires — modelled onsrc/components/pipeline/reports.vue, including its empty-state convention (96px grey icon +text-h5heading).v-alert, reusing the clipboard pattern fromGetStartedSteps.vue(copiedKey+ 1.5smdi-checkswap). It does not auto-dismiss, because the token cannot be recovered afterwards.GET /whoamireportspublisheroradmin. This is UX only —POST /api/tokensis what actually enforces it.All calls go through the existing
apiFetch(path, { method, body })insrc/composables/api.js, which already attaches the bearer. No new HTTP layer./profile/tokens→TokensView, withbeforeEnter: authGuard.Registered only in the
isAuthEnabledbranch, exactly like/profile. The routes array is duplicated across both branches of anif, and API tokens are meaningless on an open instance.<v-list-item prepend-icon="mdi-key" title="Tokens" to="/profile/tokens">in the account menu, between Profile and Logout.A line under the Authenticate step linking to
/profile/tokens, shown only when auth is enabled.Two things worth knowing if you touch this:
<router-link>in the template, not an<a href>inside the step'sv-htmldescription. The app usescreateWebHistory, not hash routing, so a raw anchor would trigger a full page reload and ignoregetAppBasePath().isAuthEnabledis a module-level constant, so it had to be exposed throughcomputedfor the template to see it under the Options API.Also updated the sample env var from
your_token_heretoudash_pat_..., and noted thatudash loginprompts for the token or takes--token.Test
To test this pull request, you can run the following commands:
Additional Information
Tradeoff
Potential improvement