@tempoxyz/auth 0.0.0-pr-55.sha-7bfa693 → 0.0.0-pr-57.sha-ef01b41
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 +5 -5
- package/dist/Actions.js +4 -4
- package/dist/Auth.d.ts +1 -1
- package/dist/Auth.js +1 -1
- package/dist/actions/device.js +3 -3
- package/dist/actions/email.js +2 -2
- package/dist/actions/provider.js +2 -2
- package/dist/actions/tempoAccount.js +2 -2
- package/dist/internal/api.d.ts +0 -5
- package/dist/internal/api.js +1 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,14 +47,14 @@ pnpm add @tempoxyz/auth viem
|
|
|
47
47
|
|
|
48
48
|
## Before you start
|
|
49
49
|
|
|
50
|
-
- **Register the app.** Create a WorkOS Connect app in the Tempo Issuer environment, and register every redirect URI it uses. Its `client_id` is the `clientId`
|
|
50
|
+
- **Register the app.** Create a WorkOS Connect app in the Tempo Issuer environment, and register every redirect URI it uses. Its `client_id` is the `clientId` that `Auth.create` takes. An app with a backend also receives a client secret.
|
|
51
51
|
- **Allow the app's origin.** Tempo Auth allows the origins of every first-party Connect app's `http(s)` redirect URIs, within about three minutes of a change. A mobile app has no origin, and registers its custom scheme as its redirect URI instead.
|
|
52
52
|
|
|
53
53
|
The CLI device grant needs neither. It signs in as Tempo Auth's own `tempo-cli` app.
|
|
54
54
|
|
|
55
55
|
## Access keys
|
|
56
56
|
|
|
57
|
-
Each sign-in creates a key for the app and
|
|
57
|
+
Each sign-in creates a key for the app and requests that Tempo Auth authorize it on the user's Tempo Account. The optional `permissions` option specifies what the key may do, with viem's `Expiry` and `Scopes` helpers. Tempo Auth fills every field it leaves out with the headless ceiling:
|
|
58
58
|
|
|
59
59
|
| Field | Meaning |
|
|
60
60
|
| --------- | ----------------------------------------------------------------------------------------------------------- |
|
|
@@ -63,9 +63,9 @@ Each sign-in creates a key for the app and asks Tempo Auth to authorize it on th
|
|
|
63
63
|
| `limits` | One-time spending limits per token, such as `[{ limit: 10_000_000n, token }]`. Defaults to about $1,000 of each token the `scopes` call, or of OUSD |
|
|
64
64
|
| `scopes` | The calls the key may make, such as `[Scopes.tip20(token).transfer()]`. Defaults to transfers of each token the key limits |
|
|
65
65
|
|
|
66
|
-
In a browser, the key is a non-extractable WebCrypto P256 key, so no script can read its private key. A CLI, a native app, or a backend
|
|
66
|
+
In a browser, the key is a non-extractable WebCrypto P256 key, so no script can read its private key. A CLI, a native app, or a backend uses a secp256k1 key, which it stores as a string.
|
|
67
67
|
|
|
68
|
-
To authorize a key the app already holds, pass it as `accessKey`, a viem account. The library never
|
|
68
|
+
To authorize a key the app already holds, pass it as `accessKey`, a viem account. The library never reads its private key. Its `access` names the Tempo Account, which defaults to the user's first:
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
const accessKey = Account.fromWebCryptoP256(keyPair, { access: tempoAccount })
|
|
@@ -215,7 +215,7 @@ Refresh tokens rotate, so save the new tokens over the old ones after each refre
|
|
|
215
215
|
|
|
216
216
|
## Errors
|
|
217
217
|
|
|
218
|
-
A request Tempo Auth refuses throws `Auth.RequestError`. It carries the OAuth error code as `code`, and `message`
|
|
218
|
+
A request Tempo Auth refuses throws `Auth.RequestError`. It carries the OAuth error code as `code`, and `message` states the fault and its fix. `reason`, `field`, and `meta` let an app branch on the refusal and read the values it compared. [Errors](../../docs/errors.md) lists every `reason`.
|
|
219
219
|
|
|
220
220
|
```ts
|
|
221
221
|
try {
|
package/dist/Actions.js
CHANGED
|
@@ -18,14 +18,14 @@ export * as tempoAccount from './actions/tempoAccount.js';
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export async function authorize(auth, options = {}) {
|
|
21
|
-
// Checking the session first
|
|
22
|
-
const session = await Api.json(await (auth.fetch ?? fetch)(new URL(
|
|
21
|
+
// Checking the session first avoids a failed request for a visitor without one.
|
|
22
|
+
const session = await Api.json(await (auth.fetch ?? fetch)(new URL('/v1/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, '/v1/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, '/v1/auth/logout', { json: {} }));
|
|
65
65
|
}
|
package/dist/Auth.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class RequestError extends Error {
|
|
|
32
32
|
readonly meta: Readonly<Record<string, number | string>> | undefined;
|
|
33
33
|
/** A stable name for the refusal, to branch on. */
|
|
34
34
|
readonly reason: RequestError.Reason | undefined;
|
|
35
|
-
/** The HTTP status Tempo Auth
|
|
35
|
+
/** The HTTP status of Tempo Auth's response. */
|
|
36
36
|
readonly status: number;
|
|
37
37
|
/** The page that explains the error. */
|
|
38
38
|
readonly uri: string | undefined;
|
package/dist/Auth.js
CHANGED
|
@@ -40,7 +40,7 @@ export class RequestError extends Error {
|
|
|
40
40
|
meta;
|
|
41
41
|
/** A stable name for the refusal, to branch on. */
|
|
42
42
|
reason;
|
|
43
|
-
/** The HTTP status Tempo Auth
|
|
43
|
+
/** The HTTP status of Tempo Auth's response. */
|
|
44
44
|
status;
|
|
45
45
|
/** The page that explains the error. */
|
|
46
46
|
uri;
|
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, '/v1/device/authorize', {
|
|
19
19
|
json: {
|
|
20
20
|
device: options.device,
|
|
21
21
|
key_authorization: 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, '/v1/device/token', {
|
|
34
34
|
json: { device_code: code.device_code },
|
|
35
35
|
});
|
|
36
36
|
const body = (await response.json());
|
|
@@ -40,7 +40,7 @@ export async function authorize(auth, options) {
|
|
|
40
40
|
key_authorization: body.key_authorization,
|
|
41
41
|
tokens: Api.tokens(body),
|
|
42
42
|
}, key);
|
|
43
|
-
// RFC 8628
|
|
43
|
+
// RFC 8628 requires a client that receives `slow_down` to add 5 seconds to its interval.
|
|
44
44
|
if (body.error === 'slow_down')
|
|
45
45
|
interval += 5;
|
|
46
46
|
else if (body.error !== 'authorization_pending')
|
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, '/v1/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, '/v1/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('/v1/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(`/v1/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
|
}
|
|
@@ -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, '/v1/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('/v1/account', auth.url), {
|
|
28
28
|
credentials: 'include',
|
|
29
29
|
}));
|
|
30
30
|
return tempo.map(({ address }) => ({ address }));
|
package/dist/internal/api.d.ts
CHANGED
|
@@ -37,11 +37,6 @@ 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";
|
|
45
40
|
/**
|
|
46
41
|
* Calls Tempo Auth's OAuth token endpoint, adding the client and any secret. It forwards standard
|
|
47
42
|
* OAuth form posts to WorkOS.
|
package/dist/internal/api.js
CHANGED
|
@@ -27,7 +27,7 @@ export function authorization(body, options) {
|
|
|
27
27
|
}
|
|
28
28
|
/** Reads a JSON response, and throws a {@link RequestError} for a refused request. */
|
|
29
29
|
export async function json(response) {
|
|
30
|
-
// Some refusals, such as the CSRF check's,
|
|
30
|
+
// Some refusals, such as the CSRF check's, return plain text.
|
|
31
31
|
const body = (await response.json().catch(() => ({})));
|
|
32
32
|
if (!response.ok)
|
|
33
33
|
throw error(body, { status: response.status });
|
|
@@ -60,11 +60,6 @@ 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';
|
|
68
63
|
/**
|
|
69
64
|
* Calls Tempo Auth's OAuth token endpoint, adding the client and any secret. It forwards standard
|
|
70
65
|
* 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-57.sha-ef01b41",
|
|
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": {
|