Skip to content

Commit

Permalink
Various OAuth related fixes (bluesky-social#2871)
Browse files Browse the repository at this point in the history
* wip

* tidy

* tidy

* tidy

* Update packages/oauth/oauth-client/src/session-getter.ts

Co-authored-by: devin ivy <[email protected]>

* fix combineSignals

* tidy

* tidy

* improve typing of atprotoScopeSchema

* stronger typings

* tidy

* ci

* Fix cors error

* downgrade ioredis dependency

* fix ioredis version

* tidy

---------

Co-authored-by: devin ivy <[email protected]>
  • Loading branch information
matthieusieben and devinivy authored Oct 18, 2024
1 parent 7f26b17 commit 9d40ccb
Show file tree
Hide file tree
Showing 76 changed files with 587 additions and 351 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-radios-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Add missing "wap" display request parameter value
5 changes: 5 additions & 0 deletions .changeset/light-books-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Perform issuer validation _before_ refreshing tokens.
5 changes: 5 additions & 0 deletions .changeset/moody-dots-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Remove invalid `client_id` property from oauthRefreshTokenGrantTokenRequestSchema
5 changes: 5 additions & 0 deletions .changeset/nasty-olives-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/pds": patch
---

Add Access-Control-Allow-Headers to .well-known/oauth-protected-resource response
5 changes: 5 additions & 0 deletions .changeset/odd-suns-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Ensure token response is properly typed according to the atproto OAuth spec
7 changes: 7 additions & 0 deletions .changeset/perfect-icons-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@atproto/oauth-client-browser": minor
"@atproto/oauth-client-node": minor
"@atproto/oauth-client": minor
---

Use `"auto"` instead of `undefined` to descibe the refresh mechanism to use in various methods.
5 changes: 5 additions & 0 deletions .changeset/shaggy-mugs-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Allow using different ioredis version
7 changes: 7 additions & 0 deletions .changeset/shiny-news-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@atproto-labs/handle-resolver": patch
"@atproto/oauth-provider": patch
"@atproto/oauth-client": patch
---

Use fetch()'s "cache" option instead of headers to force caching behavior
5 changes: 5 additions & 0 deletions .changeset/spicy-dingos-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Do not use cache when checking sub authority
5 changes: 5 additions & 0 deletions .changeset/stupid-frogs-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/did": patch
---

Add atprotoDidSchema to validate Atproto supported DID's using zod
5 changes: 5 additions & 0 deletions .changeset/twenty-paws-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": minor
---

Remove invalid `issuer` property from OAuthTokenResponse
5 changes: 5 additions & 0 deletions .changeset/wicked-moose-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Allow all oauth request parameters to be used as authorize() options
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@swc/core": "^1.3.42",
"@swc/jest": "^0.2.24",
"@types/jest": "^28.1.4",
"@types/node": "^18.19.50",
"@types/node": "^18.19.56",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"dotenv": "^16.0.3",
Expand All @@ -48,7 +48,7 @@
"pino-pretty": "^9.1.0",
"prettier": "^3.2.5",
"prettier-config-standard": "^7.0.0",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"@atproto/lex-cli": "workspace:^",
"jest": "^28.1.2",
"prettier": "^3.2.5",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"uint8arrays": "3.0.0"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/bsky/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"axios": "^0.27.2",
"jest": "^28.1.2",
"ts-node": "^10.8.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/bsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"get-port": "^5.1.1",
"jest": "^28.1.2",
"ts-node": "^10.8.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/common-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"devDependencies": {
"jest": "^28.1.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"devDependencies": {
"jest": "^28.1.2",
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"uint8arrays": "3.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"devDependencies": {
"@atproto/common": "workspace:^",
"jest": "^28.1.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/dev-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
},
"devDependencies": {
"@types/express": "^4.17.13",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/did/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
6 changes: 6 additions & 0 deletions packages/did/src/atproto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { z } from 'zod'

import { InvalidDidError } from './did-error.js'
import { Did } from './did.js'
import {
Expand All @@ -13,6 +15,10 @@ import {
export type AtprotoIdentityDidMethods = 'plc' | 'web'
export type AtprotoDid = Did<AtprotoIdentityDidMethods>

export const atprotoDidSchema = z
.string()
.refine(isAtprotoDid, `Atproto only allows "plc" and "web" DID methods`)

export function isAtprotoDid(input: unknown): input is AtprotoDid {
// Optimized equivalent of:
// return isDidPlc(input) || isAtprotoDidWeb(input)
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"express": "^4.18.2",
"get-port": "^6.1.2",
"jest": "^28.1.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/internal/did-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/fetch-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@types/psl": "1.1.3",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@atproto-labs/pipe": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"optionalDependencies": {
"zod": "^3.23.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/handle-resolver-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@atproto/did": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/handle-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ export class AppViewHandleResolver implements HandleResolver {
)
url.searchParams.set('handle', handle)

const headers = new Headers()
if (options?.noCache) headers.set('cache-control', 'no-cache')

const response = await this.fetch.call(null, url, {
headers,
cache: options?.noCache ? 'no-cache' : undefined,
signal: options?.signal,
redirect: 'error',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ export class WellKnownHandleResolver implements HandleResolver {
): Promise<ResolvedHandle> {
const url = new URL('/.well-known/atproto-did', `https://${handle}`)

const headers = new Headers()
if (options?.noCache) headers.set('cache-control', 'no-cache')

try {
const response = await this.fetch.call(null, url, {
headers,
cache: options?.noCache ? 'no-cache' : undefined,
signal: options?.signal,
redirect: 'error',
})
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/identity-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@atproto/syntax": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/pipe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"rollup": "^4.10.0",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/simple-store-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lru-cache": "^10.2.0"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/simple-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/lex-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/lexicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
},
"devDependencies": {
"jest": "^28.1.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/oauth/jwk-jose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"jose": "^5.2.0"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/jwk-webcrypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@atproto/jwk-jose": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/jwk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/oauth-client-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@atproto/oauth-types": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/oauth-client-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ needs of your application, and must respect the [ATPROTO].
The `client_metadata` object will typically be built by the backend at startup.

```ts
import { NodeOAuthClient } from '@atproto/oauth-client-node'
import { NodeOAuthClient, Session } from '@atproto/oauth-client-node'
import { JoseKey } from '@atproto/jwk-jose'

const client = new NodeOAuthClient({
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/oauth-client-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@atproto/oauth-types": "workspace:*"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/oauth-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For a node specific implementation, see
### Configuration

```ts
import { OAuthClient } from '@atproto/oauth-client'
import { OAuthClient, Key, Session } from '@atproto/oauth-client'
import { JoseKey } from '@atproto/jwk-jose' // NodeJS/Browser only
const client = new OAuthClient({
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/oauth-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"scripts": {
"build": "tsc --build tsconfig.build.json"
Expand Down
Loading

0 comments on commit 9d40ccb

Please sign in to comment.