You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ee87bcf
Browse filesBrowse the repository at this point in the historyBrowse files
Teach deploying-boxes to set up Sign in with Amp from an orb with manage_amp
- In an orb, create the client with manage_amp oauth_clients create, which stores its ID and secret on the deployment
- Set deployment secrets and env vars with manage_amp secrets and environment_variables and a deployment
- Keep configure-sign-in.sh and amp secrets set for the user's own machine
Amp-Thread-ID: https://ampcode.com/threads/T-3d47889d-1857-4618-a7b5-8641a960b093
Co-authored-by: Thorsten Ball <thorsten@ampcode.com>
Copy file name to clipboardExpand all lines: skills/deploying-boxes/SKILL.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,13 +82,21 @@ Report the deployment URL, the Box, the deployed commit, and what you verified.
82
82
83
83
## Secrets and environment variables
84
84
85
-
Deployment secrets need an existing deployment. For an app that needs secrets before it can start, run the first deploy (it may fail), set the secrets, then deploy again:
85
+
Deployment secrets need an existing deployment. For an app that needs secrets before it can start, run the first deploy (it may fail), set the secrets, then deploy again.
86
+
87
+
In an orb, Amp refuses `amp secrets set` and other CLI commands that change the owner's account, so set values with `manage_amp`:
88
+
89
+
- A secret: topic `secrets`, operation `set`, with `scope: box`, `box: <namespace>/<box>`, `deployment: <deployment>`, and `name`. For a value the user or a third party provides, omit `generated_value`; the user enters it in a masked dialog and it never enters the thread. For a value you generate, such as a session key, pass it as `generated_value`.
90
+
- A non-secret value: topic `environment_variables`, operation `set`, with the same scope fields plus `value`.
91
+
- `list`on either topic shows the names stored at that scope.
Omit `--deployment` to set a Box value that every deployment on the Box receives. A deployment on a workspace Box also receives the workspace's secrets. Deployment values override Box values, which override workspace values; sibling deployments do not share values. Changes take effect on the next deploy. `amp secrets list` and `amp secrets history` take the same flags. Pass values through a file or standard input, and never commit or print secret values.
99
+
Omit the deployment (`deployment` or `--deployment`) to set a Box value that every deployment on the Box receives. A deployment on a workspace Box also receives the workspace's secrets. Deployment values override Box values, which override workspace values; sibling deployments do not share values, so set an app's values on its deployment. Changes take effect on the next deploy. `amp secrets list` and `amp secrets history` take the same flags. Pass CLI values through a file or standard input, and never commit or print secret values.
92
100
93
101
## Private deployments
94
102
@@ -129,7 +137,9 @@ Check that `amp boxes deploy --help` lists `--domain`; if it does not, run `amp
129
137
130
138
Sign in with Amp is a separate OAuth client owned by an Amp workspace, not part of the deployment. Register a client whose redirect URI is under the deployment URL, store the client ID and secret as deployment secrets, and redeploy. A new deployment name, Box, or custom domain changes the URL, so update the redirect URIs to match. Any Amp account can sign in to such an app; to limit who can use it, make the deployment private or allow only listed users in the app, as the template does with `APP_ALLOWED_USER_IDS`.
131
139
132
-
Read `reference/sign-in-with-amp.md` before adding it. It covers the bundled `template/` (a tested SvelteKit starter), `scripts/configure-sign-in.sh`, which creates the client and stores its credentials without printing the secret, manual setup, and verification.
140
+
In an orb, create the client with `manage_amp` topic `oauth_clients`, operation `create`. After the user approves in a dialog, it creates the client and stores its ID and secret on the deployment without returning the secret. Operation `update` changes its redirect URIs. `scripts/configure-sign-in.sh` does the same with the CLI and runs only on the user's own machine.
141
+
142
+
Read `reference/sign-in-with-amp.md` before adding it. It covers the bundled `template/` (a tested SvelteKit starter), registering the client, manual setup, and verification.
Copy file name to clipboardExpand all lines: skills/deploying-boxes/reference/sign-in-with-amp.md
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,13 +31,27 @@ Then:
31
31
32
32
Creating a Sign in with Amp client needs workspace admin in the workspace that will own the client. Users who sign in to the app do not need to belong to that workspace. If the user is not an admin of any workspace, stop and tell them; use "Manual credentials" only with a client someone else created.
33
33
34
-
After the first deploy, run:
34
+
The app needs three deployment variables: `AMP_OAUTH_CLIENT_ID` (env), `AMP_OAUTH_CLIENT_SECRET` (secret), and `APP_SESSION_SECRET` (secret, at least 32 random characters). The redirect URI is the deployment's `url` from `amp boxes deployments` plus `/auth/callback`, which is `https://<deployment>--<namespace>.onamp.dev/auth/callback` unless the deployment has a custom domain. Never print, log, or paste the client secret; Amp cannot show it again.
35
+
36
+
### In an orb
37
+
38
+
Amp refuses `amp oauth-clients create` and `amp secrets set` in an orb, so the script below fails there. After the first deploy, use `manage_amp`:
39
+
40
+
1. Topic `oauth_clients`, operation `create`, with `workspace`, `name` (the deployment name works), `redirect_uris` (a list holding the redirect URI), `box` (`<namespace>/<box>`), and `deployment`. The user approves in a dialog. It creates a server-side client and stores `AMP_OAUTH_CLIENT_ID` and `AMP_OAUTH_CLIENT_SECRET` on the deployment; the result has the client ID but never the secret.
41
+
2. Topic `secrets`, operation `set`, with `scope: box`, the same `box` and `deployment`, `name: APP_SESSION_SECRET`, and a random value you generate as `generated_value` (for example from `openssl rand -base64 48`).
42
+
3. Topic `secrets`, operation `list`, and topic `environment_variables`, operation `list`, with the same scope fields, to check that the three names are there. Then redeploy with `amp boxes deploy`.
43
+
44
+
If `create` reports that it created the client but could not store a value, do not create a second client; follow the instructions in its error. `manage_amp` is unavailable in a multiplayer thread; tell the user to run these steps from their own thread that is not multiplayer, or to use "Manual credentials".
The script checks that the deployment exists, creates a `server` (confidential) OAuth client whose redirect URI is `https://<deployment>--<namespace>.onamp.dev/auth/callback`, and stores three deployment variables: `AMP_OAUTH_CLIENT_ID` (env), `AMP_OAUTH_CLIENT_SECRET` (secret), and a generated `APP_SESSION_SECRET` (secret). It prints only the client ID, redirect URI, and manage URL. For a deployment with a custom domain, pass its `url` from `amp boxes deployments` as a fourth argument. Never print, log, or paste the client secret; Amp cannot show it again. If the script fails after it created the client, do not create a second client; finish with "Manual credentials".
54
+
The script checks that the deployment exists, creates the client, and stores the three variables, with a generated `APP_SESSION_SECRET`. It prints only the client ID, redirect URI, and manage URL. For a deployment with a custom domain, pass its `url` from `amp boxes deployments` as a fourth argument. If the script fails after it created the client, do not create a second client; finish with "Manual credentials".
41
55
42
56
Check `amp secrets list --box <namespace>/<box> --deployment <deployment>` shows the three names, then redeploy with `amp boxes deploy` so the service receives them.
These commands run only on the user's own machine. In an orb, store the client ID with `manage_amp` topic `environment_variables`, operation `set`, and the secrets with topic `secrets`, operation `set`, each with `scope: box`, `box`, and `deployment`. For the client secret, omit `generated_value` so the user enters it in a masked dialog.
69
+
54
70
### Existing apps and changed URLs
55
71
56
72
- An app not built from the template needs the same flow. Use `template/src/lib/server/oauth.ts` as the reference: issuer `https://auth.ampcode.com` with its `/oauth2/authorize`, `/oauth2/token`, and `/oauth2/jwks` endpoints, PKCE with S256, scopes `openid profile email offline_access`, and `resource=https://ampcode.com/api/v2`. Amp accepts the access token only when that resource was requested. Verify the ID token, keep tokens on the server, and refresh them.
57
-
- The redirect URI must match the deployment URL exactly. A new deployment name, Box, or custom domain changes the URL; the `onamp.dev` URL of a deployment with a custom domain redirects to it, so register only the custom one. Update the client with `amp oauth-clients edit <id> --workspace <workspace> --redirect-uri <uri>`, which replaces the list, so repeat `--redirect-uri` for every URI to keep. `amp oauth-clients list --workspace <workspace>` shows names and IDs only, and fails without `--workspace`. To see a client's redirect URIs, use `manage_amp` with topic `oauth_clients` and operation `list` where it is available, or the workspace's applications page at `https://ampcode.com/workspaces/<workspace>/applications`.
73
+
- The redirect URI must match the deployment URL exactly. A new deployment name, Box, or custom domain changes the URL; the `onamp.dev` URL of a deployment with a custom domain redirects to it, so register only the custom one. Update the client with `manage_amp` topic `oauth_clients`, operation `update`, with `workspace`, `client` (its ID or client ID), and `redirect_uris`; on the user's own machine, `amp oauth-clients edit <id> --workspace <workspace> --redirect-uri <uri>` does the same. Both replace the whole list, so include every URI to keep. `amp oauth-clients list --workspace <workspace>` shows names and IDs only, and fails without `--workspace`. To see a client's redirect URIs, use `manage_amp` with topic `oauth_clients` and operation `list`, or the workspace's applications page at `https://ampcode.com/workspaces/<workspace>/applications`.
58
74
- For local development, copy `.env.example` to `.env` and add `http://localhost:3000/auth/callback` as an additional redirect URI on the same client. Keep the production URI first.
59
75
- Undeploying or deleting a Box does not delete the OAuth client.
0 commit comments