Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/llm-wiki/08-auth-and-terms-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Platform UI auth and JupyterHub auth are related but separate:
8. Hub sets its own session cookie (SameSite=Lax, Secure by default). Any valid Keycloak user for the Hub client is currently allowed (`allow_all = True`).
9. Before spawn, Hub injects the Keycloak access token into the notebook pod as `MIP_TOKEN`, refreshing via stored refresh tokens when needed.
10. Running notebooks can refresh `MIP_TOKEN` through Hub `/notebook/hub/api/platform-token` via the mip client transport.
11. Remote use (account page): shown when `GET /services/auth-config` answers (the backend has a public Keycloak client, `KEYCLOAK_CLI_CLIENT_ID`). "Create access token" runs an authorization-code sign-in with PKCE as that client (`scope=openid offline_access`, redirect back to `/account`, code exchanged by the browser, `cli-token.ts`) and shows the offline refresh token once; nothing stores it. Users paste it into `mip login --token` or `MIP_API_TOKEN`; the mip client renews access with Keycloak itself. The page also explains `mip login` (device flow). JupyterHub is not involved.
11. Remote use (account page): shown when `GET /services/auth-config` answers (the backend has a public Keycloak client, `KEYCLOAK_CLI_CLIENT_ID`). "Create access token" runs an authorization-code sign-in with PKCE as that client (`scope=openid offline_access`, `prompt=login` so Keycloak re-asks for the password even with a live SSO session (first present on master after commit 8b17318, 2026-11-06 — use that build or newer as the minimum UI version in the M6 gate), redirect back to `/account`, code exchanged by the browser, `cli-token.ts`) and shows the offline refresh token once; nothing stores it. Users paste it into `mip login --token` or `MIP_API_TOKEN`; the mip client renews access with Keycloak itself. The page also explains `mip login` (device flow). JupyterHub is not involved.

Key files: `src/app/pages/notebook/hub-session.ts`, `hub-http.ts`, `jupyterhub-api.ts`, `nginx.conf.template`.

Expand Down
15 changes: 12 additions & 3 deletions src/app/pages/account-page/account-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ <h3>Use MIP from your own computer</h3>
<div class="remote-options">
<div class="remote-option">
<h4>No browser on that machine</h4>
<p class="remote-note">
This token works like your password for up to 180 days. Keep it only in
<code>mip login --token</code>; never put it in notebooks, <code>.env</code> files,
repositories or chat. Lost it or your computer?
<a class="account-link" [href]="authConfig()!.issuer + '/account/applications'" target="_blank"
rel="noopener">See and remove computers signed in to MIP</a>.
</p>
<button class="create-token-btn" type="button" (click)="createToken()" [disabled]="creatingToken()">
<i class="fas fa-key"></i>
<span>{{ creatingToken() ? 'Creating…' : 'Create access token' }}</span>
Expand All @@ -83,8 +90,10 @@ <h4>No browser on that machine</h4>
</div>
<span class="copy-status" aria-live="polite">{{ tokenCopyStatus() }}</span>
<p class="remote-note">
Treat it like a password: it gives your full MIP data access for up to 6 months, until
it goes unused for 30 days, or until you run <code>mip logout</code>.
It lasts up to 180 days, or until it is unused for 30 days, or until you run
<code>mip logout</code>. Lost it or your computer?
<a class="account-link" [href]="authConfig()!.issuer + '/account/applications'" target="_blank"
rel="noopener">See and remove computers signed in to MIP</a>.
</p>
}
<p class="remote-text">
Expand All @@ -108,7 +117,7 @@ <h4>A browser on any device</h4>
<pre><code>import mip
client = mip.Client.from_env()</code></pre>
<p class="remote-note">
Each sign-in lasts at most 6 months, and ends after 30 days without use. To end it sooner,
Each sign-in lasts at most 180 days, and ends after 30 days without use. To end it sooner,
run <code>mip logout</code> on that computer. Without that computer, remove
"MIP command line" under Applications in your
<a class="account-link" [href]="authConfig()!.issuer + '/account/applications'" target="_blank"
Expand Down
47 changes: 42 additions & 5 deletions src/app/pages/account-page/account-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,48 @@ describe('AccountPageComponent', () => {
expect(el.querySelector('.token-value')).toBeNull();
});

it('links to the Keycloak account page to end every computer\'s sign-in', () => {
const link = (render().nativeElement as HTMLElement).querySelector<HTMLAnchorElement>('.account-link')!;
it('links to the Keycloak applications page wherever it offers to remove computers', () => {
const links = (render().nativeElement as HTMLElement).querySelectorAll<HTMLAnchorElement>('.account-link');

expect(links.length).toBeGreaterThanOrEqual(2);
links.forEach((link) => {
expect(link.getAttribute('href')).toBe('https://idp.example/realms/MIP/account/applications');
expect(link.target).toBe('_blank');
expect(link.rel).toBe('noopener');
});
});

it('warns above the button that the token is a 180-day password kept only in mip login --token', () => {
const el: HTMLElement = render().nativeElement;

const guide = el.querySelector('.create-token-btn')!.previousElementSibling!;
expect(guide.textContent).toContain('180 days');
expect(guide.textContent).toContain('mip login --token');
});

it('states next to the shown token how it ends, instead of repeating the warning', () => {
const fixture = render();
fixture.componentInstance.cliToken.set('offline-token');
fixture.detectChanges();

const note = (fixture.nativeElement as HTMLElement).querySelector('.token-value')!.closest('.snippet')!
.nextElementSibling!.nextElementSibling!;
expect(note.tagName).toBe('P');
expect(note.textContent).toContain('180 days');
expect(note.textContent).toContain('30 days');
expect(note.textContent).toContain('mip logout');
expect(note.textContent).toContain('See and remove computers signed in to MIP');
expect(note.textContent).not.toContain('works like your password');
});

it('clears the shown token when the page is left', () => {
const fixture = render();
fixture.componentInstance.cliToken.set('offline-token');
fixture.detectChanges();

fixture.destroy();

expect(link.getAttribute('href')).toBe('https://idp.example/realms/MIP/account/applications');
expect(link.target).toBe('_blank');
expect(link.rel).toBe('noopener');
expect(fixture.componentInstance.cliToken()).toBe('');
});

it('starts the token sign-in at Keycloak as the public client', async () => {
Expand All @@ -81,6 +117,7 @@ describe('AccountPageComponent', () => {
const url = new URL(redirect.mock.calls[0][0]);
expect(url.origin + url.pathname).toBe('https://idp.example/realms/MIP/protocol/openid-connect/auth');
expect(url.searchParams.get('client_id')).toBe('mip-cli');
expect(url.searchParams.get('prompt')).toBe('login');
expect(url.searchParams.get('redirect_uri')).toBe(`${window.location.origin}/account`);
});

Expand Down
9 changes: 7 additions & 2 deletions src/app/pages/account-page/account-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, computed, inject, signal, WritableSignal } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, computed, inject, signal, WritableSignal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { CommonModule, Location } from '@angular/common';
import { HttpClient } from '@angular/common/http';
Expand All @@ -14,7 +14,7 @@ import { AuthConfig, cliTokenSignInUrl, finishCliTokenSignIn, isSignInReturn } f
styleUrl: './account-page.component.css',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AccountPageComponent {
export class AccountPageComponent implements OnDestroy {
public authService = inject(AuthService);
private location = inject(Location);
private http = inject(HttpClient);
Expand Down Expand Up @@ -51,6 +51,11 @@ export class AccountPageComponent {
}
}

ngOnDestroy(): void {
// Drop the shown token right away; the signal is only ever held until the page is left.
this.cliToken.set('');
}

async createToken(): Promise<void> {
const config = this.authConfig();
if (!config) return;
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/account-page/cli-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('cli-token', () => {
expect(url.searchParams.get('client_id')).toBe('mip-cli-handson');
expect(url.searchParams.get('response_type')).toBe('code');
expect(url.searchParams.get('scope')).toBe('openid offline_access');
expect(url.searchParams.get('prompt')).toBe('login');
expect(url.searchParams.get('redirect_uri')).toBe(redirectUri);
expect(url.searchParams.get('code_challenge_method')).toBe('S256');
expect(url.searchParams.get('code_challenge')).toMatch(/^[A-Za-z0-9_-]{43}$/);
Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/account-page/cli-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export async function cliTokenSignInUrl(config: AuthConfig, redirectUri: string)
client_id: config.clientId,
response_type: 'code',
scope: 'openid offline_access',
// Re-ask for the password even when the browser has a live SSO session, so a
// borrowed or stolen laptop cannot mint a token from the open session.
prompt: 'login',
redirect_uri: redirectUri,
state: pending.state,
code_challenge: await codeChallenge(pending.verifier),
Expand Down
Loading