@tempoxyz/auth 0.0.0-pr-47.sha-e4eead6 → 0.0.0-pr-44.sha-110ca2b
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/README.md +2 -0
- package/dist/Actions.js +3 -3
- package/dist/actions/device.js +2 -2
- package/dist/actions/email.js +2 -2
- package/dist/actions/provider.js +2 -2
- package/dist/actions/redirect.js +8 -7
- package/dist/actions/tempoAccount.js +2 -2
- package/dist/internal/api.d.ts +5 -0
- package/dist/internal/api.js +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -241,6 +241,8 @@ try {
|
|
|
241
241
|
| `storage` | Where `redirect.start` keeps its state, without serializing it. Defaults to IndexedDB |
|
|
242
242
|
| `fetch` | Calls Tempo Auth. Defaults to the global `fetch` |
|
|
243
243
|
|
|
244
|
+
The actions call version 1 of Tempo Auth's JSON API, under `/v1`. [API versions](../../docs/versioning.md) describes versions and the deprecation policy.
|
|
245
|
+
|
|
244
246
|
### `Actions`
|
|
245
247
|
|
|
246
248
|
Each sign-in flow has its own namespace. The actions every flow shares sit at the top level. Every action that creates a key also takes optional `accessKey` and `permissions`.
|
package/dist/Actions.js
CHANGED
|
@@ -19,13 +19,13 @@ export * as tempoAccount from './actions/tempoAccount.js';
|
|
|
19
19
|
*/
|
|
20
20
|
export async function authorize(auth, options = {}) {
|
|
21
21
|
// Checking the session first answers a visitor without one with no failed request.
|
|
22
|
-
const session = await Api.json(await (auth.fetch ?? fetch)(new URL(
|
|
22
|
+
const session = await Api.json(await (auth.fetch ?? fetch)(new URL(`${Api.prefix}/auth/session`, auth.url), {
|
|
23
23
|
credentials: 'include',
|
|
24
24
|
}));
|
|
25
25
|
if (!session.user)
|
|
26
26
|
return undefined;
|
|
27
27
|
const key = await AccessKey.resolve(options.accessKey);
|
|
28
|
-
const response = await Api.post(auth,
|
|
28
|
+
const response = await Api.post(auth, `${Api.prefix}/authorize`, {
|
|
29
29
|
json: request(auth, {
|
|
30
30
|
accessKey: key.accessKey,
|
|
31
31
|
permissions: options.permissions,
|
|
@@ -61,5 +61,5 @@ export async function refresh(auth, options) {
|
|
|
61
61
|
*/
|
|
62
62
|
export async function signOut(auth) {
|
|
63
63
|
// A JSON body keeps the request out of Tempo Auth's CSRF check for cross-site form posts.
|
|
64
|
-
await Api.json(await Api.post(auth,
|
|
64
|
+
await Api.json(await Api.post(auth, `${Api.prefix}/auth/logout`, { json: {} }));
|
|
65
65
|
}
|
package/dist/actions/device.js
CHANGED
|
@@ -15,7 +15,7 @@ import { request } from '../internal/request.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export async function authorize(auth, options) {
|
|
17
17
|
const key = await AccessKey.resolve(options.accessKey);
|
|
18
|
-
const code = await Api.json(await Api.post(auth,
|
|
18
|
+
const code = await Api.json(await Api.post(auth, `${Api.prefix}/device/authorize`, {
|
|
19
19
|
json: {
|
|
20
20
|
device: options.device,
|
|
21
21
|
keyAuthorization: request(auth, {
|
|
@@ -30,7 +30,7 @@ export async function authorize(auth, options) {
|
|
|
30
30
|
const deadline = Date.now() + code.expires_in * 1000;
|
|
31
31
|
while (Date.now() < deadline) {
|
|
32
32
|
await new Promise((resolve) => setTimeout(resolve, interval * 1000));
|
|
33
|
-
const response = await Api.post(auth,
|
|
33
|
+
const response = await Api.post(auth, `${Api.prefix}/device/token`, {
|
|
34
34
|
json: { device_code: code.device_code },
|
|
35
35
|
});
|
|
36
36
|
const body = (await response.json());
|
package/dist/actions/email.js
CHANGED
|
@@ -10,7 +10,7 @@ import { request } from '../internal/request.js';
|
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
12
|
export async function sendCode(auth, options) {
|
|
13
|
-
await Api.json(await Api.post(auth,
|
|
13
|
+
await Api.json(await Api.post(auth, `${Api.prefix}/auth/code`, { json: options }));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Signs the user in with the code they were emailed, and authorizes the app in the same call.
|
|
@@ -25,7 +25,7 @@ export async function sendCode(auth, options) {
|
|
|
25
25
|
export async function signIn(auth, options) {
|
|
26
26
|
const { code, email, permissions } = options;
|
|
27
27
|
const key = await AccessKey.resolve(options.accessKey);
|
|
28
|
-
const body = await Api.json(await Api.post(auth,
|
|
28
|
+
const body = await Api.json(await Api.post(auth, `${Api.prefix}/auth/code/verify`, {
|
|
29
29
|
json: {
|
|
30
30
|
authorize: request(auth, { accessKey: key.accessKey, permissions }),
|
|
31
31
|
code,
|
package/dist/actions/provider.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as Api from '../internal/api.js';
|
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
11
|
export async function list(auth) {
|
|
12
|
-
const { providers } = await Api.json(await (auth.fetch ?? fetch)(new URL(
|
|
12
|
+
const { providers } = await Api.json(await (auth.fetch ?? fetch)(new URL(`${Api.prefix}/auth/providers`, auth.url)));
|
|
13
13
|
return providers;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -25,7 +25,7 @@ export async function list(auth) {
|
|
|
25
25
|
export function signIn(auth, options) {
|
|
26
26
|
const url = 'url' in options
|
|
27
27
|
? new URL(options.url)
|
|
28
|
-
: new URL(
|
|
28
|
+
: new URL(`${Api.prefix}/auth/oauth/${options.provider}`, auth.url);
|
|
29
29
|
url.searchParams.set('return_to', options.returnTo ?? window.location.href);
|
|
30
30
|
window.location.assign(url);
|
|
31
31
|
}
|
package/dist/actions/redirect.js
CHANGED
|
@@ -99,6 +99,14 @@ export async function createUrl(auth, options = {}) {
|
|
|
99
99
|
export async function handleCallback(auth, options) {
|
|
100
100
|
const { redirectUri, state, verifier, ...material } = options.pending;
|
|
101
101
|
const params = new URL(options.url).searchParams;
|
|
102
|
+
// State comes first, so a forged link cannot supply the error an app shows.
|
|
103
|
+
if (params.get('state') !== state)
|
|
104
|
+
throw new RequestError({
|
|
105
|
+
code: 'invalid_request',
|
|
106
|
+
field: 'state',
|
|
107
|
+
message: 'Invalid `state` in the callback URL. Start sign-in again from this app.',
|
|
108
|
+
status: 400,
|
|
109
|
+
});
|
|
102
110
|
const code = params.get('code');
|
|
103
111
|
if (!code)
|
|
104
112
|
throw new RequestError({
|
|
@@ -108,13 +116,6 @@ export async function handleCallback(auth, options) {
|
|
|
108
116
|
'Missing `code` in the callback URL. Start sign-in again.',
|
|
109
117
|
status: 400,
|
|
110
118
|
});
|
|
111
|
-
if (params.get('state') !== state)
|
|
112
|
-
throw new RequestError({
|
|
113
|
-
code: 'invalid_request',
|
|
114
|
-
field: 'state',
|
|
115
|
-
message: 'Invalid `state` in the callback URL. Start sign-in again from this app.',
|
|
116
|
-
status: 400,
|
|
117
|
-
});
|
|
118
119
|
const body = await Api.token(auth, {
|
|
119
120
|
code,
|
|
120
121
|
code_verifier: verifier,
|
|
@@ -12,7 +12,7 @@ import * as Api from '../internal/api.js';
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export async function create(auth) {
|
|
15
|
-
const { address } = await Api.json(await Api.post(auth,
|
|
15
|
+
const { address } = await Api.json(await Api.post(auth, `${Api.prefix}/account/tempo`, { json: {} }));
|
|
16
16
|
return { address };
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -24,7 +24,7 @@ export async function create(auth) {
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export async function list(auth) {
|
|
27
|
-
const { tempo } = await Api.json(await (auth.fetch ?? fetch)(new URL(
|
|
27
|
+
const { tempo } = await Api.json(await (auth.fetch ?? fetch)(new URL(`${Api.prefix}/account`, auth.url), {
|
|
28
28
|
credentials: 'include',
|
|
29
29
|
}));
|
|
30
30
|
return tempo.map(({ address }) => ({ address }));
|
package/dist/internal/api.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export declare function error(body: Partial<ErrorBody>, options: {
|
|
|
37
37
|
export declare function post(auth: Auth, path: string, options: {
|
|
38
38
|
json?: unknown;
|
|
39
39
|
}): Promise<Response>;
|
|
40
|
+
/**
|
|
41
|
+
* The path prefix of the Tempo Auth API version the package calls. Every JSON route starts with it,
|
|
42
|
+
* and the OAuth endpoints under `/oauth2` do not.
|
|
43
|
+
*/
|
|
44
|
+
export declare const prefix = "/v1";
|
|
40
45
|
/**
|
|
41
46
|
* Calls Tempo Auth's OAuth token endpoint, adding the client and any secret. It forwards standard
|
|
42
47
|
* OAuth form posts to WorkOS.
|
package/dist/internal/api.js
CHANGED
|
@@ -60,6 +60,11 @@ export function post(auth, path, options) {
|
|
|
60
60
|
method: 'POST',
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The path prefix of the Tempo Auth API version the package calls. Every JSON route starts with it,
|
|
65
|
+
* and the OAuth endpoints under `/oauth2` do not.
|
|
66
|
+
*/
|
|
67
|
+
export const prefix = '/v1';
|
|
63
68
|
/**
|
|
64
69
|
* Calls Tempo Auth's OAuth token endpoint, adding the client and any secret. It forwards standard
|
|
65
70
|
* OAuth form posts to WorkOS.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempoxyz/auth",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-44.sha-110ca2b",
|
|
4
4
|
"description": "Signs users in to Tempo through Tempo Auth, and returns viem access key accounts on their Tempo Accounts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|