Skip to content

Commit

Permalink
OAuth spec alignment (bluesky-social#2755)
Browse files Browse the repository at this point in the history
* Improve reporting of metadata validation error
* Properly validate client metadata scope
* Allow loopback clients to define their scopes through client_id query parameters
* Require definition of "scope" in client metadata document
* Restrict the value used as code_challenge_methods_supported
* Remove `plain` from `code_challenge_methods_supported`
* Prevent use of empty string in unsupported oidc request parameters
* Centralize parsing of client metadata error
* Enfore code_challenge_method=S256 request parameter
* Improve error description in case of invalid loopback client_id
* Enfore single scope query param in loopback clients
* Disable request params scopes defaulting to client metadata scope
* Centralize loopback client validation logic
* add assertion utils for client ids
* Improve invalid client_id error messages from BrowserOAuthClient.from()
* Use scope from client metadata as default value
* Improve client side validation of client metadata
* Allow fetching of source maps files from browser debugger
* Use the clientId to configure the OAuth client
* Allow native clients to use https: redirect uris
* Explicitely forbid MTLS client auth method
* Improve error feedback in case of invalid client_id domain name
* Remove un-spec'ed restrictions on redirect_uris based on the client_uri
* Do not strip query string from URL after oauth redirect in fragment mode
* Add missing "expires_in" property to OAuthParResponse type definition
* Allow non canonical urls to be used as client ID
* Allow client metadata to contain other return type values than "code"
* Properly validate request_uri request parameter
* Improve parsing and validation of client_id's
* Return "invalid_client" on invalid client credentials
* improved error management & reporting
* performance improvement
* Allow loopback client ids to omit the (empty) path parameter

Co-authored-by: devin ivy <[email protected]>
  • Loading branch information
matthieusieben and devinivy authored Sep 26, 2024
1 parent 87a1f24 commit ed325d8
Show file tree
Hide file tree
Showing 102 changed files with 1,768 additions and 1,176 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-rules-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Disable request params scopes defaulting to client metadata scopes. Requires that client always provide a "scope" parameter when initiating an oauth flow.
5 changes: 5 additions & 0 deletions .changeset/calm-planets-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Properly validate client metadata scope
5 changes: 5 additions & 0 deletions .changeset/chatty-adults-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Allow ClientID query params to end with a slash "/" char
5 changes: 5 additions & 0 deletions .changeset/curly-maps-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Remove "plain" from code_challenge_methods_supported
5 changes: 5 additions & 0 deletions .changeset/curly-tomatoes-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client-browser": patch
---

Improve invalid client_id error messages from BrowserOAuthClient.from()
5 changes: 5 additions & 0 deletions .changeset/cyan-pandas-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Require definition of "scope" in client metadata document
5 changes: 5 additions & 0 deletions .changeset/fair-hornets-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Improve reporting of metadata validation error
5 changes: 5 additions & 0 deletions .changeset/famous-items-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Expose OAuthScope
5 changes: 5 additions & 0 deletions .changeset/four-crews-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Improve client side validation of client metadata
5 changes: 5 additions & 0 deletions .changeset/friendly-suits-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client-browser": patch
---

Do not strip query string from URL after oauth redirect in fragment mode
5 changes: 5 additions & 0 deletions .changeset/giant-ladybugs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

add assertion utils for client ids
5 changes: 5 additions & 0 deletions .changeset/gold-taxis-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Properly validate request_uri request parameter
5 changes: 5 additions & 0 deletions .changeset/gorgeous-hounds-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Allow loopback client ids to omit the (empty) path parameter
5 changes: 5 additions & 0 deletions .changeset/great-news-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Enforce ClientID URL path to be normalized
5 changes: 5 additions & 0 deletions .changeset/late-wolves-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Enforce code_challenge_method=S256 request parameter
5 changes: 5 additions & 0 deletions .changeset/mighty-keys-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Rename OAuthAuthenticationRequestParameters to OAuthAuthorizationRequestParameters
5 changes: 5 additions & 0 deletions .changeset/odd-moons-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Use scope from client metadata as default value
5 changes: 5 additions & 0 deletions .changeset/purple-penguins-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Explicitely forbid MTLS client auth method
5 changes: 5 additions & 0 deletions .changeset/quick-eels-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Restrict the value used as code_challenge_methods_supported
5 changes: 5 additions & 0 deletions .changeset/quick-singers-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Return "invalid_client" on invalid client credentials
5 changes: 5 additions & 0 deletions .changeset/rude-apes-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Prevent use of empty string in unsupported oidc request parameters
5 changes: 5 additions & 0 deletions .changeset/shy-balloons-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Add missing "expires_in" property to OAuthParResponse type definition
5 changes: 5 additions & 0 deletions .changeset/silly-sloths-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Allow fetching of source maps files from browser debugger
5 changes: 5 additions & 0 deletions .changeset/smart-houses-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Allow loopback clients to define their scopes through the "scope" client_id query parameter.
5 changes: 5 additions & 0 deletions .changeset/sweet-dodos-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-types": patch
---

Improve error description in case of invalid loopback client_id
5 changes: 5 additions & 0 deletions .changeset/tasty-singers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Allow native clients to use https: redirect uris
5 changes: 5 additions & 0 deletions .changeset/three-elephants-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Allow client metadata to contain other values than "code"
5 changes: 5 additions & 0 deletions .changeset/yellow-ants-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client-browser": patch
---

Relax type restriction on clientId option
4 changes: 3 additions & 1 deletion packages/oauth/oauth-client-browser/example/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAuthContext } from './auth/auth-provider'
import { OAuthSession } from '@atproto/oauth-client'

function App() {
const { pdsAgent, signOut } = useAuthContext()
const { pdsAgent, signOut, refresh } = useAuthContext()

const hasTokenInfo = pdsAgent.sessionManager instanceof OAuthSession

Expand Down Expand Up @@ -69,6 +69,8 @@ function App() {
</pre>
</code>

<button onClick={refresh}>Refresh tokens</button>
<br />
<button onClick={signOut}>Sign-out</button>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useOAuth, UseOAuthOptions } from './oauth/use-oauth'
export type AuthContext = {
pdsAgent: Agent
signOut: () => void
refresh: () => void
}

const AuthContext = createContext<AuthContext | null>(null)
Expand All @@ -27,23 +28,42 @@ export const AuthProvider = ({
agent: oauthAgent,
signIn: oauthSignIn,
signOut: oauthSignOut,
refresh: oauthRefresh,
} = useOAuth(options)

const {
agent: credentialAgent,
signIn: credentialSignIn,
signOut: credentialSignOut,
refresh: credentialRefresh,
} = useCredentialAuth()

const value = useMemo<AuthContext | null>(
() =>
oauthAgent
? { pdsAgent: oauthAgent, signOut: oauthSignOut }
: credentialAgent
? { pdsAgent: credentialAgent, signOut: credentialSignOut }
: null,
[oauthAgent, oauthSignOut, credentialAgent, credentialSignOut],
)
const value = useMemo<AuthContext | null>(() => {
if (oauthAgent) {
return {
pdsAgent: oauthAgent,
signOut: oauthSignOut,
refresh: oauthRefresh,
}
}

if (credentialAgent) {
return {
pdsAgent: credentialAgent,
signOut: credentialSignOut,
refresh: credentialRefresh,
}
}

return null
}, [
oauthAgent,
oauthSignOut,
credentialAgent,
credentialSignOut,
oauthRefresh,
credentialRefresh,
])

if (isLoginPopup) {
return <div>This window can be closed</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export function useCredentialAuth() {
)

return useMemo(
() => ({ agent, signIn, signOut: () => agent?.logout() }),
() => ({
agent,
signIn,
signOut: () => agent?.logout(),
refresh: () => agent?.sessionManager.refreshSession(),
}),
[signIn, agent],
)
}
Expand Down
Loading

0 comments on commit ed325d8

Please sign in to comment.