Skip to content

Fix authentication error handling#56

Open
ThisIsMissEm wants to merge 6 commits intoChimeHQ:mainfrom
germ-network:fix/authentication-error-handling
Open

Fix authentication error handling#56
ThisIsMissEm wants to merge 6 commits intoChimeHQ:mainfrom
germ-network:fix/authentication-error-handling

Conversation

@ThisIsMissEm
Copy link
Copy Markdown
Contributor

This lifts up the checks for:

Fixes handling of OAuth Errors, since this is generic, and fixes #36.

ThisIsMissEm and others added 6 commits March 6, 2026 16:29
This also ensures we clearly signal to the DPoP request method whether we are talking to an authorization server or a resource server (since these give different OAuth Error responses).

The test coverage has increased dramatically here.
This is actually generic OAuth token response logic, but the package is currently structured to make this bluesky specific.
This allows apps using the Bluesky client to retrieve the DID for the authenticated account from the Login.
Comment on lines +340 to +345
if let state = state {
if state != stateToken {
throw AuthenticatorError.stateTokenMismatch(state, stateToken)
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be safe to remove this guard, since all authorization servers should pass through the state parameter to the redirect.

@mattmassicotte let me know if you'd agree with my assessment and then we can remove this check with:

Suggested change
if let state = state {
if state != stateToken {
throw AuthenticatorError.stateTokenMismatch(state, stateToken)
}
}
if state != stateToken {
throw AuthenticatorError.stateTokenMismatch(state, stateToken)
}

let errorDescription = redirectParams.firstQueryValue("error_description")

if let error = error {
switch error.lowercased() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some additional errors here: https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1

Comment on lines +358 to +361
// We do actually have error and error_description parameters, so
// could create a more specific error than missingAuthorizationCode
throw AuthenticatorError.missingAuthorizationCode
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to pass back the complete error such that other code could handle it potentially:

Suggested change
// We do actually have error and error_description parameters, so
// could create a more specific error than missingAuthorizationCode
throw AuthenticatorError.missingAuthorizationCode
}
throw AuthenticatorError.unrecognizedError(error, errorDescription ?? "")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect handling for denied authorization attempts

2 participants