@aiveth/nextjs 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +19 -0
- package/dist/client.d.ts +30 -2
- package/dist/client.js +32 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +2 -0
- package/dist/handlers.d.ts +5 -0
- package/dist/handlers.js +21 -2
- package/dist/here.d.ts +87 -0
- package/dist/here.js +92 -0
- package/dist/oidc.d.ts +1 -0
- package/dist/oidc.js +3 -1
- package/dist/proxy.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0 — unreleased
|
|
4
|
+
|
|
5
|
+
- `signInHere` in `@aiveth/nextjs/client`: the same steps as `@aiveth/react` (one shared file). The proxy's new `/auth/sign-in-here` keeps the attempt's PKCE verifier in the sealed sign-in cookie; the code the steps end with goes to `/auth/callback`, which signs the person in with your app's secret.
|
|
6
|
+
|
|
7
|
+
## 0.11.0 — unreleased
|
|
8
|
+
|
|
9
|
+
- `/auth/login` passes `invitation` on to Aiveth. Set your app's sign-in page to `https://your-app/auth/login` in the Aiveth console, and invitations made for the app work with no code of yours.
|
|
10
|
+
- `loginHint` now opens Aiveth's page on that address's ways in, skipping the address screen.
|
|
11
|
+
|
|
3
12
|
## 0.10.0 — 2026-11-28
|
|
4
13
|
|
|
5
14
|
- `/auth/login` passes `connection`, `login_hint`, `ui_locales` and `screen_hint=sign-up` to Aiveth (`login_hint` was sent before but Aiveth ignored it; it now fills in the address). `<SignInButton>` / `<AivethButton>` take the same options as `@aiveth/react`; `signInHref()` builds the link.
|
package/README.md
CHANGED
|
@@ -75,6 +75,25 @@ The buttons and `/auth/login` take `connection` (`google`, `microsoft`, `github`
|
|
|
75
75
|
organization has it on), `loginHint` (`login_hint`), `locale` (`ui_locales`) and
|
|
76
76
|
`screenHint: 'sign-up'`. `signInHref(options)` builds the link.
|
|
77
77
|
|
|
78
|
+
## Sign in on your own page
|
|
79
|
+
|
|
80
|
+
Turn on **Sign-in on your page** for the app in Aiveth. The proxy keeps the attempt's PKCE
|
|
81
|
+
verifier; the code the steps end with goes to `/auth/callback`, which signs the person in with your
|
|
82
|
+
app's secret — the same as a redirect.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
'use client';
|
|
86
|
+
import { signInHere } from '@aiveth/nextjs/client';
|
|
87
|
+
|
|
88
|
+
const { flow, step } = await signInHere.start({ email, returnTo: '/dashboard' });
|
|
89
|
+
let next = await flow.password(password); // or sendEmailCode() + verifyEmailCode(code)
|
|
90
|
+
if (next.status === 'needs_second_factor') next = await flow.secondFactor(code);
|
|
91
|
+
if (next.status === 'needs_aiveth') flow.continueOnAiveth();
|
|
92
|
+
// 'signed_in': the browser is on its way to /auth/callback
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The same steps and names as `@aiveth/react` (`signUp`, `invitation`, `sendResetCode`, …).
|
|
96
|
+
|
|
78
97
|
## Sign in in your organization's own look
|
|
79
98
|
|
|
80
99
|
```tsx
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import { HereFlow, type Step } from './here.js';
|
|
2
3
|
import type { User } from './session.js';
|
|
3
4
|
interface UseUser {
|
|
4
5
|
user: User | null;
|
|
@@ -18,12 +19,40 @@ export declare function SignedOut({ children }: {
|
|
|
18
19
|
children: ReactNode;
|
|
19
20
|
}): import("react").JSX.Element | null;
|
|
20
21
|
/** `returnTo`: where to come back after signing in (a path on this site). */
|
|
22
|
+
/** Sign-in on your own page (Aiveth's sign-in API; turn on "Sign-in on your page" for the app):
|
|
23
|
+
* each step answers the next (`Step`). The proxy keeps the attempt's PKCE verifier; the code
|
|
24
|
+
* the steps end with goes to `/auth/callback`, which signs the person in with your app's secret. */
|
|
25
|
+
export declare const signInHere: {
|
|
26
|
+
start: ({ email, returnTo, workspace }: {
|
|
27
|
+
email: string;
|
|
28
|
+
returnTo?: string;
|
|
29
|
+
workspace?: string;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
flow: HereFlow;
|
|
32
|
+
step: Step;
|
|
33
|
+
}>;
|
|
34
|
+
signUp: ({ email, returnTo }: {
|
|
35
|
+
email: string;
|
|
36
|
+
returnTo?: string;
|
|
37
|
+
}) => Promise<{
|
|
38
|
+
flow: HereFlow;
|
|
39
|
+
step: Step;
|
|
40
|
+
}>;
|
|
41
|
+
/** The `invitation` your sign-in page got (`?invitation=`): its address, then `details`. */
|
|
42
|
+
invitation: (invitation: string, { returnTo }?: {
|
|
43
|
+
returnTo?: string;
|
|
44
|
+
}) => Promise<{
|
|
45
|
+
flow: HereFlow;
|
|
46
|
+
step: Step;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
export { HereFlow, StepRefused, type Step, type StepStatus } from './here.js';
|
|
21
50
|
/** What a sign-in link may ask of Aiveth — the same names as `@aiveth/react`'s `signIn`. */
|
|
22
51
|
export interface SignInLinkOptions {
|
|
23
52
|
returnTo?: string;
|
|
24
53
|
/** Straight to Google, Microsoft, GitHub or your single sign-on — when your organization has it on. */
|
|
25
54
|
connection?: 'google' | 'microsoft' | 'github' | 'sso';
|
|
26
|
-
/** The address
|
|
55
|
+
/** The address you already know: Aiveth's page opens on its ways in. */
|
|
27
56
|
loginHint?: string;
|
|
28
57
|
/** The sign-in page's language, e.g. `'hi'`. */
|
|
29
58
|
locale?: string;
|
|
@@ -52,4 +81,3 @@ export declare function SignOutButton({ children, className }: {
|
|
|
52
81
|
export declare function UserButton({ className }: {
|
|
53
82
|
className?: string;
|
|
54
83
|
}): import("react").JSX.Element | null;
|
|
55
|
-
export {};
|
package/dist/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
5
5
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
6
6
|
import { BrandedButton, useBrandLook } from './brand.js';
|
|
7
7
|
import { ROUTES } from './config.js';
|
|
8
|
+
import { HereFlow, StepRefused } from './here.js';
|
|
8
9
|
const Ctx = createContext(null);
|
|
9
10
|
/** `initialUser`: pass `await getUser()` from a Server Component to skip the first fetch. */
|
|
10
11
|
export function AivethProvider({ children, initialUser }) {
|
|
@@ -42,6 +43,37 @@ export function SignedOut({ children }) {
|
|
|
42
43
|
const { user, loading } = useUser();
|
|
43
44
|
return !loading && !user ? _jsx(_Fragment, { children: children }) : null;
|
|
44
45
|
}
|
|
46
|
+
/** `returnTo`: where to come back after signing in (a path on this site). */
|
|
47
|
+
/** Sign-in on your own page (Aiveth's sign-in API; turn on "Sign-in on your page" for the app):
|
|
48
|
+
* each step answers the next (`Step`). The proxy keeps the attempt's PKCE verifier; the code
|
|
49
|
+
* the steps end with goes to `/auth/callback`, which signs the person in with your app's secret. */
|
|
50
|
+
export const signInHere = {
|
|
51
|
+
start: ({ email, returnTo, workspace }) => begun({ returnTo, workspace }, (flow, request) => flow.begin(request, email)),
|
|
52
|
+
signUp: ({ email, returnTo }) => begun({ returnTo }, (flow, request) => flow.beginSignUp(request, email)),
|
|
53
|
+
/** The `invitation` your sign-in page got (`?invitation=`): its address, then `details`. */
|
|
54
|
+
invitation: (invitation, { returnTo } = {}) => begun({ returnTo }, (flow, request) => flow.beginInvitation(request, invitation)),
|
|
55
|
+
};
|
|
56
|
+
async function begun(where, first) {
|
|
57
|
+
const q = new URLSearchParams();
|
|
58
|
+
if (where.returnTo)
|
|
59
|
+
q.set('returnTo', where.returnTo);
|
|
60
|
+
if (where.workspace)
|
|
61
|
+
q.set('workspace', where.workspace);
|
|
62
|
+
const res = await fetch(`${ROUTES.signInHere}${q.size ? `?${q}` : ''}`, { credentials: 'same-origin', cache: 'no-store' });
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
throw new StepRefused(res.status, 'Sign-in on this page is not set up.');
|
|
65
|
+
const set = (await res.json());
|
|
66
|
+
const navigate = (url) => { window.location.assign(url); };
|
|
67
|
+
const flow = new HereFlow({
|
|
68
|
+
baseUrl: set.baseUrl, clientId: set.clientId, fetch: (u, i) => fetch(u, i), navigate,
|
|
69
|
+
finish: async (code, state) => {
|
|
70
|
+
navigate(`${ROUTES.callback}?${new URLSearchParams({ code, ...(state ? { state } : {}) })}`);
|
|
71
|
+
return { status: 'signed_in', returnTo: set.returnTo };
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return { flow, step: await first(flow, set.request) };
|
|
75
|
+
}
|
|
76
|
+
export { HereFlow, StepRefused } from './here.js';
|
|
45
77
|
/** `/auth/login` with these options (the proxy passes them to Aiveth). */
|
|
46
78
|
export function signInHref({ returnTo, connection, loginHint, locale, screenHint } = {}) {
|
|
47
79
|
const q = new URLSearchParams();
|
package/dist/config.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export declare const ROUTES: {
|
|
|
25
25
|
readonly session: "/auth/session";
|
|
26
26
|
/** The organization's look for this app (`AivethButton`), read from Aiveth on the server. */
|
|
27
27
|
readonly branding: "/auth/branding";
|
|
28
|
+
/** Sign-in on your own page (`signInHere`): the attempt's PKCE, state and nonce, kept here. */
|
|
29
|
+
readonly signInHere: "/auth/sign-in-here";
|
|
28
30
|
};
|
|
29
31
|
/** Use these settings instead of the environment's (or on top of them). */
|
|
30
32
|
export declare function configureAiveth(settings: Partial<AivethNextConfig>): void;
|
package/dist/config.js
CHANGED
|
@@ -6,6 +6,8 @@ export const ROUTES = {
|
|
|
6
6
|
session: '/auth/session',
|
|
7
7
|
/** The organization's look for this app (`AivethButton`), read from Aiveth on the server. */
|
|
8
8
|
branding: '/auth/branding',
|
|
9
|
+
/** Sign-in on your own page (`signInHere`): the attempt's PKCE, state and nonce, kept here. */
|
|
10
|
+
signInHere: '/auth/sign-in-here',
|
|
9
11
|
};
|
|
10
12
|
const DEFAULT_SCOPE = 'openid profile email offline_access';
|
|
11
13
|
let current = null;
|
package/dist/handlers.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ import { type CookieToSet } from './session.js';
|
|
|
4
4
|
export declare const secureFor: (c: AivethNextConfig) => boolean;
|
|
5
5
|
export declare function write(res: NextResponse, cookies: CookieToSet[]): NextResponse;
|
|
6
6
|
export declare function login(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
|
|
7
|
+
/** Sign-in on your own page (`signInHere` in `@aiveth/nextjs/client`): what the browser's steps
|
|
8
|
+
* need — Aiveth's address, this app's client id and the attempt's PKCE challenge, state and nonce.
|
|
9
|
+
* The verifier stays here, sealed in the same cookie as a redirect's; the code the steps end
|
|
10
|
+
* with comes back to `/auth/callback`, which swaps it with the app's secret as always. */
|
|
11
|
+
export declare function signInHere(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
|
|
7
12
|
export declare function callback(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
|
|
8
13
|
export declare function logout(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
|
|
9
14
|
/** Who is signed in, for the browser (`AivethProvider`): the profile only, never a token. */
|
package/dist/handlers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* The routes the proxy answers: /auth/login, /auth/callback, /auth/logout, /auth/session,
|
|
2
|
-
* /auth/branding. */
|
|
2
|
+
* /auth/branding, /auth/sign-in-here. */
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
|
-
import { ROUTES, safeReturnTo } from './config.js';
|
|
4
|
+
import { ROUTES, redirectUri, safeReturnTo } from './config.js';
|
|
5
5
|
import { AivethAuthError, authorizeUrl, challengeOf, exchangeCode, logoutUrl, randomValue } from './oidc.js';
|
|
6
6
|
import { TX_COOKIE, TX_SECONDS, clearedSessionCookies, readSession, seal, sessionCookies, txCookie, unseal, } from './session.js';
|
|
7
7
|
export const secureFor = (c) => c.appUrl.startsWith('https://');
|
|
@@ -26,10 +26,29 @@ export async function login(req, c) {
|
|
|
26
26
|
loginHint: req.nextUrl.searchParams.get('login_hint') ?? undefined,
|
|
27
27
|
locale: req.nextUrl.searchParams.get('ui_locales') ?? undefined,
|
|
28
28
|
screenHint: req.nextUrl.searchParams.get('screen_hint') ?? undefined,
|
|
29
|
+
invitation: req.nextUrl.searchParams.get('invitation') ?? undefined,
|
|
29
30
|
workspace: req.nextUrl.searchParams.get('workspace') ?? undefined,
|
|
30
31
|
});
|
|
31
32
|
return write(NextResponse.redirect(to), [txCookie(await seal(tx, c.cookieSecret, TX_SECONDS), secureFor(c))]);
|
|
32
33
|
}
|
|
34
|
+
/** Sign-in on your own page (`signInHere` in `@aiveth/nextjs/client`): what the browser's steps
|
|
35
|
+
* need — Aiveth's address, this app's client id and the attempt's PKCE challenge, state and nonce.
|
|
36
|
+
* The verifier stays here, sealed in the same cookie as a redirect's; the code the steps end
|
|
37
|
+
* with comes back to `/auth/callback`, which swaps it with the app's secret as always. */
|
|
38
|
+
export async function signInHere(req, c) {
|
|
39
|
+
const tx = {
|
|
40
|
+
state: randomValue(), nonce: randomValue(), verifier: randomValue(),
|
|
41
|
+
returnTo: safeReturnTo(req.nextUrl.searchParams.get('returnTo')),
|
|
42
|
+
};
|
|
43
|
+
const workspace = req.nextUrl.searchParams.get('workspace');
|
|
44
|
+
const request = {
|
|
45
|
+
redirect_uri: redirectUri(c), code_challenge: await challengeOf(tx.verifier), code_challenge_method: 'S256',
|
|
46
|
+
scope: c.scope, state: tx.state, nonce: tx.nonce,
|
|
47
|
+
...(workspace ? { workspace } : {}), ...(c.audience ? { resource: c.audience } : {}),
|
|
48
|
+
};
|
|
49
|
+
const res = NextResponse.json({ baseUrl: c.baseUrl, clientId: c.clientId, request, returnTo: tx.returnTo }, { headers: { 'Cache-Control': 'no-store' } });
|
|
50
|
+
return write(res, [txCookie(await seal(tx, c.cookieSecret, TX_SECONDS), secureFor(c))]);
|
|
51
|
+
}
|
|
33
52
|
export async function callback(req, c) {
|
|
34
53
|
const q = req.nextUrl.searchParams;
|
|
35
54
|
const tx = await unseal(req.cookies.get(TX_COOKIE)?.value, c.cookieSecret);
|
package/dist/here.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** What the next screen is. `signed_in`: done. `needs_aiveth`: send the browser to
|
|
2
|
+
* `continueUrl` (a step only Aiveth's page can do), or call `continueOnAiveth()`. */
|
|
3
|
+
export type StepStatus = 'needs_first_factor' | 'needs_second_factor' | 'needs_legal_acceptance' | 'needs_email_code' | 'needs_details' | 'needs_reset_code' | 'needs_new_password' | 'waiting' | 'needs_aiveth' | 'refused' | 'signed_in';
|
|
4
|
+
export interface Step {
|
|
5
|
+
status: StepStatus;
|
|
6
|
+
/** needs_first_factor: `password`, `email_code`, and `google` / `microsoft` / `github` / `sso`
|
|
7
|
+
* (for those, use `signIn({ connection })`). */
|
|
8
|
+
ways?: string[];
|
|
9
|
+
/** needs_second_factor: `authenticator`, `recovery_code`. */
|
|
10
|
+
factors?: string[];
|
|
11
|
+
/** needs_details: the fields to ask for. */
|
|
12
|
+
fields?: string[];
|
|
13
|
+
/** needs_details from an invitation: the address it was sent to. */
|
|
14
|
+
email?: string;
|
|
15
|
+
reason?: string;
|
|
16
|
+
termsUrl?: string;
|
|
17
|
+
privacyUrl?: string;
|
|
18
|
+
continueUrl?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
errorDescription?: string;
|
|
21
|
+
/** signed_in: where your app wanted to go. */
|
|
22
|
+
returnTo?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** A step Aiveth refused: `status` is the HTTP status (401 a wrong password or code, 422 a
|
|
25
|
+
* password the rules refuse, 429 too many tries, 404 the attempt ended). */
|
|
26
|
+
export declare class StepRefused extends Error {
|
|
27
|
+
readonly status: number;
|
|
28
|
+
constructor(status: number, message: string);
|
|
29
|
+
}
|
|
30
|
+
/** The authorize request the attempt stands for (PKCE, state, nonce). */
|
|
31
|
+
export interface AttemptRequest {
|
|
32
|
+
redirect_uri: string;
|
|
33
|
+
code_challenge: string;
|
|
34
|
+
code_challenge_method: 'S256';
|
|
35
|
+
scope: string;
|
|
36
|
+
state: string;
|
|
37
|
+
nonce: string;
|
|
38
|
+
workspace?: string;
|
|
39
|
+
resource?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface HereSetup {
|
|
42
|
+
baseUrl: string;
|
|
43
|
+
clientId: string;
|
|
44
|
+
fetch: typeof fetch;
|
|
45
|
+
/** The code and its state: swap them for a session; answers the `signed_in` step. */
|
|
46
|
+
finish: (code: string, state: string | null) => Promise<Step>;
|
|
47
|
+
navigate: (url: string) => void;
|
|
48
|
+
}
|
|
49
|
+
/** One sign-in, sign-up, new password or invitation on your page. Each method sends one step
|
|
50
|
+
* and answers the next; a `complete` answer is finished at once (`signed_in`). */
|
|
51
|
+
export declare class HereFlow {
|
|
52
|
+
private readonly setup;
|
|
53
|
+
private attempt;
|
|
54
|
+
private continueUrl;
|
|
55
|
+
constructor(setup: HereSetup);
|
|
56
|
+
private base;
|
|
57
|
+
private send;
|
|
58
|
+
private at;
|
|
59
|
+
/** @internal Begin with the address (a sign-in) — through `signInHere.start`. */
|
|
60
|
+
begin(request: AttemptRequest, email: string): Promise<Step>;
|
|
61
|
+
/** @internal Begin a sign-up — through `signInHere.signUp`. */
|
|
62
|
+
beginSignUp(request: AttemptRequest, email: string): Promise<Step>;
|
|
63
|
+
/** @internal Begin from an invitation link's token — through `signInHere.invitation`. */
|
|
64
|
+
beginInvitation(request: AttemptRequest, invitation: string): Promise<Step>;
|
|
65
|
+
password(password: string): Promise<Step>;
|
|
66
|
+
sendEmailCode(): Promise<Step>;
|
|
67
|
+
verifyEmailCode(code: string): Promise<Step>;
|
|
68
|
+
/** The authenticator code, or one recovery code. */
|
|
69
|
+
secondFactor(code: string): Promise<Step>;
|
|
70
|
+
/** The person ticked your organization's terms (never tick it for them). */
|
|
71
|
+
acceptTerms(): Promise<Step>;
|
|
72
|
+
/** "Forgot password?": a code to the address — the same answer for any address. */
|
|
73
|
+
sendResetCode(): Promise<Step>;
|
|
74
|
+
verifyResetCode(code: string): Promise<Step>;
|
|
75
|
+
setNewPassword(password: string): Promise<Step>;
|
|
76
|
+
/** Sign-up: the code Aiveth emailed. */
|
|
77
|
+
verifySignUpCode(code: string): Promise<Step>;
|
|
78
|
+
resendSignUpCode(): Promise<Step>;
|
|
79
|
+
/** Sign-up or invitation: the name and a password. */
|
|
80
|
+
details(d: {
|
|
81
|
+
firstName: string;
|
|
82
|
+
lastName?: string;
|
|
83
|
+
password: string;
|
|
84
|
+
}): Promise<Step>;
|
|
85
|
+
/** After `needs_aiveth`: the rest on Aiveth's page, then back to your app. */
|
|
86
|
+
continueOnAiveth(): void;
|
|
87
|
+
}
|
package/dist/here.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* Sign-in on your own page (Aiveth's sign-in API, `/v1/sign-in/{client_id}/…`): the steps of a
|
|
2
|
+
* sign-in, a sign-up, a new password or an invitation, each answering a `Step`. The same file
|
|
3
|
+
* is in `@aiveth/react` and `@aiveth/nextjs` — keep them equal. Only `finish` differs: the code
|
|
4
|
+
* is swapped for tokens in the browser (React, PKCE) or by your server (Next.js `/auth/callback`). */
|
|
5
|
+
/** A step Aiveth refused: `status` is the HTTP status (401 a wrong password or code, 422 a
|
|
6
|
+
* password the rules refuse, 429 too many tries, 404 the attempt ended). */
|
|
7
|
+
export class StepRefused extends Error {
|
|
8
|
+
status;
|
|
9
|
+
constructor(status, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.name = 'StepRefused';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** One sign-in, sign-up, new password or invitation on your page. Each method sends one step
|
|
16
|
+
* and answers the next; a `complete` answer is finished at once (`signed_in`). */
|
|
17
|
+
export class HereFlow {
|
|
18
|
+
setup;
|
|
19
|
+
attempt = '';
|
|
20
|
+
continueUrl = '';
|
|
21
|
+
constructor(setup) {
|
|
22
|
+
this.setup = setup;
|
|
23
|
+
}
|
|
24
|
+
base() {
|
|
25
|
+
return `${this.setup.baseUrl}/v1/sign-in/${encodeURIComponent(this.setup.clientId)}`;
|
|
26
|
+
}
|
|
27
|
+
async send(path, body) {
|
|
28
|
+
const res = await this.setup.fetch(`${this.base()}${path}`, {
|
|
29
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
31
|
+
});
|
|
32
|
+
let said;
|
|
33
|
+
try {
|
|
34
|
+
said = (await res.json());
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new StepRefused(res.status, `Aiveth answered ${res.status}.`);
|
|
38
|
+
}
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
throw new StepRefused(res.status, typeof said.detail === 'string' ? said.detail : `Aiveth answered ${res.status}.`);
|
|
41
|
+
if (said.attempt)
|
|
42
|
+
this.attempt = said.attempt;
|
|
43
|
+
if (said.status === 'complete')
|
|
44
|
+
return this.setup.finish(said.code ?? '', said.state ?? null);
|
|
45
|
+
if (said.continue_url)
|
|
46
|
+
this.continueUrl = said.continue_url;
|
|
47
|
+
return {
|
|
48
|
+
status: said.status, ways: said.ways, factors: said.factors, fields: said.fields,
|
|
49
|
+
email: said.email, reason: said.reason, termsUrl: said.terms_url, privacyUrl: said.privacy_url,
|
|
50
|
+
continueUrl: said.continue_url, error: said.error, errorDescription: said.error_description,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
at(kind, step) {
|
|
54
|
+
return `/${kind}/${encodeURIComponent(this.attempt)}/${step}`;
|
|
55
|
+
}
|
|
56
|
+
/** @internal Begin with the address (a sign-in) — through `signInHere.start`. */
|
|
57
|
+
begin(request, email) {
|
|
58
|
+
return this.send('/attempts', { ...request, email });
|
|
59
|
+
}
|
|
60
|
+
/** @internal Begin a sign-up — through `signInHere.signUp`. */
|
|
61
|
+
beginSignUp(request, email) {
|
|
62
|
+
return this.send('/sign-ups', { ...request, email });
|
|
63
|
+
}
|
|
64
|
+
/** @internal Begin from an invitation link's token — through `signInHere.invitation`. */
|
|
65
|
+
beginInvitation(request, invitation) {
|
|
66
|
+
return this.send('/invitations', { ...request, invitation });
|
|
67
|
+
}
|
|
68
|
+
password(password) { return this.send(this.at('attempts', 'password'), { password }); }
|
|
69
|
+
sendEmailCode() { return this.send(this.at('attempts', 'email-code')); }
|
|
70
|
+
verifyEmailCode(code) { return this.send(this.at('attempts', 'email-code/verify'), { code }); }
|
|
71
|
+
/** The authenticator code, or one recovery code. */
|
|
72
|
+
secondFactor(code) { return this.send(this.at('attempts', 'second-factor'), { code }); }
|
|
73
|
+
/** The person ticked your organization's terms (never tick it for them). */
|
|
74
|
+
acceptTerms() { return this.send(this.at('attempts', 'terms'), { accepted: true }); }
|
|
75
|
+
/** "Forgot password?": a code to the address — the same answer for any address. */
|
|
76
|
+
sendResetCode() { return this.send(this.at('attempts', 'reset-password')); }
|
|
77
|
+
verifyResetCode(code) { return this.send(this.at('attempts', 'reset-password/verify'), { code }); }
|
|
78
|
+
setNewPassword(password) { return this.send(this.at('attempts', 'reset-password/new'), { password }); }
|
|
79
|
+
/** Sign-up: the code Aiveth emailed. */
|
|
80
|
+
verifySignUpCode(code) { return this.send(this.at('sign-ups', 'verify'), { code }); }
|
|
81
|
+
resendSignUpCode() { return this.send(this.at('sign-ups', 'email-code')); }
|
|
82
|
+
/** Sign-up or invitation: the name and a password. */
|
|
83
|
+
details(d) {
|
|
84
|
+
return this.send(this.at('sign-ups', 'details'), { first_name: d.firstName, last_name: d.lastName ?? '', password: d.password });
|
|
85
|
+
}
|
|
86
|
+
/** After `needs_aiveth`: the rest on Aiveth's page, then back to your app. */
|
|
87
|
+
continueOnAiveth() {
|
|
88
|
+
if (!this.continueUrl)
|
|
89
|
+
throw new StepRefused(409, 'Nothing waits on Aiveth\'s page.');
|
|
90
|
+
this.setup.navigate(this.continueUrl);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/dist/oidc.d.ts
CHANGED
package/dist/oidc.js
CHANGED
|
@@ -55,11 +55,13 @@ export async function authorizeUrl(c, a) {
|
|
|
55
55
|
if (a.connection)
|
|
56
56
|
q.set('connection', a.connection); // straight to that way in (google, microsoft, github, sso)
|
|
57
57
|
if (a.loginHint)
|
|
58
|
-
q.set('login_hint', a.loginHint); // the address
|
|
58
|
+
q.set('login_hint', a.loginHint); // the card opens on that address's ways in
|
|
59
59
|
if (a.locale)
|
|
60
60
|
q.set('ui_locales', a.locale); // the sign-in page's language
|
|
61
61
|
if (a.screenHint === 'sign-up')
|
|
62
62
|
q.set('prompt', 'create'); // the sign-up page, where people may join
|
|
63
|
+
if (a.invitation)
|
|
64
|
+
q.set('invitation', a.invitation); // an invitation email's: join, then back here
|
|
63
65
|
if (a.workspace)
|
|
64
66
|
q.set('workspace', a.workspace); // signed in to that workspace (a member's only)
|
|
65
67
|
if (c.audience)
|
package/dist/proxy.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* page, the Route Handler, the Server Action) — CVE-2025-29927 slipped past middleware alone. */
|
|
6
6
|
import { NextResponse } from 'next/server';
|
|
7
7
|
import { ROUTES, config } from './config.js';
|
|
8
|
-
import { brandingJson, callback, login, logout, secureFor, sessionJson, write } from './handlers.js';
|
|
8
|
+
import { brandingJson, callback, login, logout, secureFor, sessionJson, signInHere, write } from './handlers.js';
|
|
9
9
|
import { refreshSession } from './oidc.js';
|
|
10
10
|
import { clearedSessionCookies, now, readSession, sessionCookies } from './session.js';
|
|
11
11
|
/** A new access token this long before the old one ends. */
|
|
@@ -44,6 +44,8 @@ export function aivethProxy(options = {}) {
|
|
|
44
44
|
return sessionJson(req, c);
|
|
45
45
|
if (path === ROUTES.branding)
|
|
46
46
|
return brandingJson(req, c);
|
|
47
|
+
if (path === ROUTES.signInHere)
|
|
48
|
+
return signInHere(req, c);
|
|
47
49
|
let session = await readSession(req.cookies, c.cookieSecret);
|
|
48
50
|
let cookies = [];
|
|
49
51
|
if (session) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiveth/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Official Aiveth SDK for Next.js: sign in on Aiveth's page, an encrypted session cookie, and the signed-in user on the server and in the browser.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Aiveth team",
|