@tempoxyz/auth 0.0.0-pr-56.sha-5ef7958 → 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 +1 -1
- package/dist/Auth.d.ts +1 -1
- package/dist/Auth.js +1 -1
- package/dist/actions/device.js +1 -1
- package/dist/internal/api.js +1 -1
- 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,7 +18,7 @@ export * as tempoAccount from './actions/tempoAccount.js';
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export async function authorize(auth, options = {}) {
|
|
21
|
-
// Checking the session first
|
|
21
|
+
// Checking the session first avoids a failed request for a visitor without one.
|
|
22
22
|
const session = await Api.json(await (auth.fetch ?? fetch)(new URL('/v1/auth/session', auth.url), {
|
|
23
23
|
credentials: 'include',
|
|
24
24
|
}));
|
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
|
@@ -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/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 });
|
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": {
|