@tempoxyz/auth 0.0.0-pr-7.sha-59fc900 → 0.0.0-pr-9.sha-9005488

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 CHANGED
@@ -43,9 +43,10 @@ pnpm add @tempoxyz/auth viem
43
43
 
44
44
  ## Before you start
45
45
 
46
- - **Register the app.** Add it to Tempo Auth's `apps.config.ts`, with every redirect URI it uses, and mark it `headless` if it calls Tempo Auth from its own page. Merging creates its WorkOS Connect app, whose `client_id` is the `clientId` you pass to `Auth.create`. An app with a backend also needs a client secret from the WorkOS dashboard.
46
+ - **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` you pass to `Auth.create`. An app with a backend also gets a client secret.
47
+ - **Allow the app's origin.** Apps that call Tempo Auth from their own page need their origin in Tempo Auth's `INTERNAL_ORIGINS`. A mobile app has no origin, and registers its custom scheme as its redirect URI instead.
47
48
 
48
- The CLI device grant needs no registration. It signs in as Tempo Auth's own `tempo-cli` app.
49
+ The CLI device grant needs neither. It signs in as Tempo Auth's own `tempo-cli` app.
49
50
 
50
51
  ## Access keys
51
52
 
@@ -100,6 +101,37 @@ const authorization = await Actions.handleRedirect(auth)
100
101
 
101
102
  `redirect` keeps its state in session storage until the browser returns. Pass `storage` to `Auth.create` to keep it elsewhere.
102
103
 
104
+ ### A mobile app
105
+
106
+ For a React Native or Expo app. It calls the same actions as a browser app, with no `Origin`, and opens Tempo Auth's pages in the system browser, which returns to the app's custom scheme. Import `react-native-get-random-values` first, since keys need `crypto.getRandomValues`.
107
+
108
+ ```ts
109
+ import * as WebBrowser from 'expo-web-browser'
110
+
111
+ const auth = Auth.create({
112
+ clientId: 'client_…',
113
+ redirectUri: 'my-app://callback',
114
+ url: 'https://auth.tempo.xyz',
115
+ })
116
+
117
+ // Your own sign-in UI, as in a browser.
118
+ await Actions.sendCode(auth, { email })
119
+ const result = await Actions.verifyCode(auth, { accessKey, code, email })
120
+
121
+ // Or Tempo Auth's pages, which also offer Google and SSO.
122
+ const { pending, url } = await Actions.createAuthorizationUrl(auth, {
123
+ accessKey,
124
+ })
125
+ const session = await WebBrowser.openAuthSessionAsync(url, auth.redirectUri)
126
+ if (session.type === 'success')
127
+ authorization = await Actions.handleCallback(auth, {
128
+ pending,
129
+ url: session.url,
130
+ })
131
+ ```
132
+
133
+ Keep the authorization in the device's secure store, as [Keep a sign-in](#keep-a-sign-in) describes.
134
+
103
135
  ### A backend
104
136
 
105
137
  For an app whose server holds a client secret. The server builds the URL, keeps the pending state until the callback, and redeems the code itself.
package/dist/Actions.js CHANGED
@@ -108,7 +108,8 @@ export async function createAuthorizationUrl(auth, options) {
108
108
  const pending = {
109
109
  privateKey: Secp256k1.randomPrivateKey(),
110
110
  redirectUri,
111
- state: crypto.randomUUID(),
111
+ // `Bytes.random` needs only `crypto.getRandomValues`, which React Native polyfills.
112
+ state: Base64.fromBytes(Bytes.random(16), base64url),
112
113
  verifier: Base64.fromBytes(Bytes.random(32), base64url),
113
114
  };
114
115
  const { client_id, keyAuthorization, scope } = request(auth, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-7.sha-59fc900",
3
+ "version": "0.0.0-pr-9.sha-9005488",
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": {