Scratch space for learning atproto app development

Compare changes

Choose any two refs to compare.

Changed files
+45 -3
src
auth
+2 -2
.env.template
···
DB_PATH=":memory:" # The SQLite database path. Set as ":memory:" to use a temporary in-memory database.
# PUBLIC_URL="" # Set when deployed publicly, e.g. "https://mysite.com". Informs OAuth client id.
# LOG_LEVEL="info" # Options: 'fatal', 'error', 'warn', 'info', 'debug'
-
# PDS_URL="https://my.pds" # The the default PDS for login and sign-ups
+
# PDS_URL="https://my.pds" # The default PDS for login and sign-ups
-
# Secrets bellow *MUST* be set in production
+
# Secrets below *MUST* be set in production
# May be generated with `openssl rand -base64 33`
# COOKIE_SECRET=""
+42
README.md
···
npm run dev
# Navigate to http://localhost:8080
```
+
+
## Deploying
+
+
In production, you will need a private key to sign OAuth tokens request. Use the
+
following command to generate a new private key:
+
+
```sh
+
./bin/gen-jwk
+
```
+
+
The generated key must be added to the environment variables (`.env` file) in `PRIVATE_KEYS`.
+
+
```env
+
PRIVATE_KEYS='[{"kty":"EC","kid":"12",...}]'
+
```
+
+
> [!NOTE]
+
>
+
> The `PRIVATE_KEYS` can contain multiple keys. The first key in the array is
+
> the most recent one, and it will be used to sign new tokens. When a key is
+
> removed, all associated sessions will be invalidated.
+
+
Make sure to also set the `COOKIE_SECRET`, which is used to sign session
+
cookies, in your environment variables (`.env` file). You should use a random
+
string for this:
+
+
```sh
+
openssl rand -base64 33
+
```
+
+
Finally, set the `PUBLIC_URL` to the URL where your app will be accessible. This
+
will allow the authorization servers to download the app's public keys.
+
+
```env
+
PUBLIC_URL="https://your-app-url.com"
+
```
+
+
> [!NOTE]
+
>
+
> You can use services like [ngrok](https://ngrok.com/) to expose your local
+
> server to the internet for testing purposes. Just set the `PUBLIC_URL` to the
+
> ngrok URL.
+1 -1
src/auth/client.ts
···
// If a keyset is defined (meaning the client is confidential). Let's make
// sure it has a private key for signing. Note: findPrivateKey will throw if
-
// the keyset does no contain a suitable private key.
+
// the keyset does not contain a suitable private key.
const pk = keyset?.findPrivateKey({ use: 'sig' })
const clientMetadata: OAuthClientMetadataInput = env.PUBLIC_URL