Warning
Under development, not ready for use ...yet
A Python library for implementing OAuth authentication with the AT Protocol (Bluesky Social).
Status: Under development - API may change
This library implements the AT Protocol OAuth authentication flow as documented in the specification.
- Handle resolution to DID
- DID document retrieval
- PDS metadata retrieval
- OAuth authorization flow with PKCE
- Pushed Authorization Requests (PAR)
- Security protections against SSRF attacks
- Comprehensive error handling
- Detailed logging
pip install atproto-oauth-authn
import atproto_oauth_authn
import webbrowser
# Get the authentication URL for a user
auth_url = atproto_oauth_authn.get_authn_url(
username="your.handle.bsky.social",
app_url="your-app.example.com"
)
# Open the browser with the authorization URL
webbrowser.open(auth_url)
- Resolve a user's handle to their DID
- Retrieve the DID document
- Extract the PDS URL from the DID document
- Get the PDS server metadata
- Extract the authorization server URL
- Get the authorization server metadata
- Generate PKCE code verifier and challenge
- Send a Pushed Authorization Request (PAR)
- Redirect the user to the authorization URL
- Handle the callback with the authorization code
- Exchange the code for access and refresh tokens
See the examples/bluesky_social_auth.py
file for a complete example of the authentication flow.
To run the example:
- Create a
.env
file with:
USERNAME=your.handle.bsky.social
APP_URL=your-app.example.com
- Run the example:
python examples/bluesky_social_auth.py
This library implements several security measures:
- PKCE (Proof Key for Code Exchange) for OAuth
- CSRF protection with state parameters
- SSRF protection for all HTTP requests
- Input validation
- Comprehensive error handling
The library uses a hierarchy of custom exceptions:
AtprotoOauthError
: Base exception for all errorsIdentityResolutionError
: Failed to resolve a user identityDidDocumentError
: Error retrieving or parsing DID documentMetadataError
: Error retrieving or parsing metadataOauthFlowError
: Error during OAuth flowSecurityError
: Security-related errorInvalidParameterError
: Invalid parameter provided to a function
MIT
Contributions are welcome! Please feel free to submit a Pull Request.