@tempoxyz/auth 0.0.0-pr-66.sha-9ef83aa → 0.0.0-pr-66.sha-b42702f

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.
@@ -103,10 +103,14 @@ export declare namespace tempoAuth {
103
103
  refresh: (options: Actions.refresh.Options) => ReturnType<typeof Actions.refresh>;
104
104
  /**
105
105
  * Rebuilds a stored authorization's account with `Key.toAccount`, sets the client's account to
106
- * it, and returns the authorization. Throws `Key.AccessKeyRequiredError` for a key that carries
106
+ * it, and returns the authorization. `Key.from` fills the key's `chainId` when a sign-in stored
107
+ * before it existed leaves it out. Throws `Key.AccessKeyRequiredError` for a key that carries
107
108
  * no material without the `accessKey` the app supplied.
108
109
  */
109
- restore: <id extends number = chainId>(authorization: Omit<Authorization<id>, 'account'>, options?: Key.toAccount.Options) => Authorization<id>;
110
+ restore: <id extends number = chainId>(authorization: Omit<Authorization<id>, 'account' | 'key'> & {
111
+ /** The stored key, with or without its `chainId`. */
112
+ key: Key.from.Value<id>;
113
+ }, options?: Key.toAccount.Options) => Authorization<id>;
110
114
  /** `Actions.signOut`, which empties the client's account, even when the request fails. */
111
115
  signOut: () => Promise<void>;
112
116
  tempoAccount: {
package/dist/Decorator.js CHANGED
@@ -80,10 +80,15 @@ export function tempoAuth(options) {
80
80
  start: (options = {}) => Actions.redirect.start(auth, options),
81
81
  },
82
82
  refresh: (options) => Actions.refresh(auth, options),
83
- restore: (authorization, options = {}) => set({
84
- ...authorization,
85
- account: Key.toAccount(authorization.key, options),
86
- }),
83
+ restore: (authorization, options = {}) => {
84
+ // A sign-in stored before `Key.chainId` existed gains it here.
85
+ const key = Key.from(authorization.key);
86
+ return set({
87
+ ...authorization,
88
+ account: Key.toAccount(key, options),
89
+ key,
90
+ });
91
+ },
87
92
  async signOut() {
88
93
  // The client stops signing even when the request fails, since the user asked to leave.
89
94
  try {
@@ -61,17 +61,13 @@ export async function jwks(auth) {
61
61
  */
62
62
  export async function userInfo(auth, options) {
63
63
  const response = await (auth.fetch ?? fetch)(new URL('/oauth2/userinfo', auth.url), { headers: { authorization: `Bearer ${options.accessToken}` } });
64
- // The issuer refuses a bad token in `WWW-Authenticate`, which may come without a body (RFC 6750 §3).
65
- if (response.status === 401) {
66
- const body = (await response
67
- .json()
68
- .catch(() => ({})));
64
+ // RFC 6750 §3 names a rejected bearer token `invalid_token`. The issuer's 401 body uses its own
65
+ // code, or none, so the refusal always carries the standard one.
66
+ if (response.status === 401)
69
67
  throw Api.error({
70
68
  error: 'invalid_token',
71
69
  error_description: 'Invalid or expired access token. Refresh the tokens, or sign in again.',
72
- ...body,
73
70
  }, { status: 401 });
74
- }
75
71
  const claims = await Api.json(response);
76
72
  return { email: claims.email, id: claims.sub };
77
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-66.sha-9ef83aa",
3
+ "version": "0.0.0-pr-66.sha-b42702f",
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": {