OAuth API
Relevant source files
The following files were used as context for generating this wiki page:
The OAuth API allows you to manage application permissions and access tokens for authenticated teams. It provides methods to list existing grants and revoke access for specific client applications. This module ensures that third-party integrations remain under the control of the Resend account owner.
Sources: src/oauth.rs:13-14, README.md:1-10
Architecture and Service Structure
The OAuthSvc struct provides the primary interface for OAuth operations. It holds an Arc<Config>, which manages the shared HTTP client, base URL, and authentication headers. Requests are built using the internal Config::build method and sent via the Config::send method, which handles rate limiting and error responses.
Sources: src/oauth.rs:13-15, src/config.rs:107-123, src/lib.rs:107-110
Service Dependency Flow
The following diagram illustrates how the OAuthSvc interacts with the core configuration to execute requests.
The Resend client exposes the OAuthSvc through a public field, allowing access to the /oauth endpoints.
Sources: src/lib.rs:107-110, src/oauth.rs:17-40
OAuth Grant Management
Grant management involves retrieving the list of permissions granted to various client IDs and removing them when necessary.
Listing OAuth Grants
The list method retrieves all OAuth grants for the authenticated team. It accepts ListOptions for filtering and pagination. By default, the limit for this endpoint is infinite, returning all current grants.
Sources: src/oauth.rs:17-26
Revoking OAuth Grants
The revoke method removes an OAuth grant using a specific oauth_grant_id. This action is performed via a DELETE request to the /oauth/grants/{id} path.
Sources: src/oauth.rs:32-40
OAuth Data Models
The API uses specific data structures to represent grants and their associated clients.
| Struct | Field | Type | Description |
|---|---|---|---|
OAuthGrant | id | OAuthGrantId | Unique identifier for the grant. |
OAuthGrant | client_id | ClientId | ID of the application receiving access. |
OAuthGrant | scopes | Vec<String> | List of permissions granted. |
OAuthGrant | revoked_at | Option<String> | Timestamp if the grant was revoked. |
OAuthGrantClient | name | String | Name of the client application. |
Sources: src/oauth.rs:46-68
Data Flow for OAuth Revocation
When you call the revoke function, the system processes the request through the shared configuration to reach the Resend API.
The sequence demonstrates the synchronous or asynchronous request flow depending on the enabled crate features.
Sources: src/oauth.rs:32-40, src/config.rs:136-150
Error Handling and Response Types
OAuth operations return specialized response types. The RevokeOAuthGrantResponse includes the ID of the revoked grant, the timestamp of revocation, and the reason for revocation.
Sources: src/oauth.rs:71-75
If a request fails due to rate limits or invalid IDs, the system returns an Error variant.
- RateLimit: Occurs when the account exceeds the allowed request frequency.
- Resend: Returns an
ErrorResponsefrom the API containing a message and status code.
Sources: src/lib.rs:242-265, src/config.rs:153-170
Implementation Example
The following code illustrates how to list and then revoke a grant using the OAuthSvc.
// Listing grants
let list_opts = ListOptions::default();
let grants = resend.oauth.list(list_opts).await?;
// Revoking a specific grant
if let Some(first_grant) = grants.data.first() {
let result = resend.oauth.revoke(&first_grant.id).await?;
println!("Revoked at: {}", result.revoked_at);
}
Sources: src/oauth.rs:88-93, src/oauth.rs:32-40
The OAuth API module provides essential controls for managing application access, ensuring secure integration with the Resend platform through controlled grant lifecycle management.
Sources: CHANGELOG.md:104-106, src/oauth.rs:1-10