OAuth Grants
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/com/resend/services/oauthgrants/OAuthGrants.java
- src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java
- src/main/java/com/resend/services/oauthgrants/model/OAuthGrantClient.java
- src/main/java/com/resend/services/oauthgrants/model/ListOAuthGrantsResponseSuccess.java
- src/main/java/com/resend/services/oauthgrants/model/RevokeOAuthGrantResponseSuccess.java
- src/main/java/com/resend/Resend.java
- src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java
The OAuth Grants module manages permissions granted to OAuth clients for an authenticated team. It allows developers to retrieve a list of active or revoked grants and perform revocation actions on specific grants.
You access this module through the main Resend client by calling the oauthGrants() method. The module interacts with the Resend API via secure HTTP requests handled by the internal HttpClient.
Sources: [Resend.java:229-231](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/Resend.java#L229-L231), [OAuthGrants.java:13-15](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrants.java#L13-L15)
Service Architecture
The OAuthGrants service extends BaseService and utilizes an IHttpClient to perform RESTful operations. It supports both standard and paginated listing of grants, as well as individual grant revocation.
Core Operations
The service provides the following methods for grant management:
| Method | Description | API Endpoint | HTTP Method |
|---|---|---|---|
list() | Retrieves all OAuth grants for the team. | /oauth/grants | GET |
list(ListParams) | Retrieves a paginated list of OAuth grants. | /oauth/grants?limit=... | GET |
revoke(String) | Revokes a specific grant by its unique ID. | /oauth/grants/{id} | DELETE |
Sources: [OAuthGrants.java:36-67](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrants.java#L36-L67), [OAuthGrantsTest.java:62-118](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrantsTest.java#L62-L118)
Request Flow
The following sequence diagram illustrates the communication flow when a developer requests a list of OAuth grants:
This diagram shows the synchronous request-response cycle mediated by the SDK's networking layer.
Sources: [OAuthGrants.java:52-55](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrants.java#L52-L55), [HttpClient.java:108-124](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/HttpClient.java#L108-L124)
Data Models
The module uses several data structures to represent grants and their associated clients.
OAuthGrant Entity
The OAuthGrant class represents the permission set and metadata for a specific integration.
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier of the OAuth grant. |
clientId | String | Identifier of the OAuth client. |
scopes | List<String> | Permissions granted (e.g., emails:send). |
resource | String | Optional resource limitation for the grant. |
createdAt | String | Timestamp of grant creation. |
revokedAt | String | Timestamp of revocation, if applicable. |
revokedReason | String | Reason for revocation (e.g., revoked_from_api). |
client | OAuthGrantClient | Metadata about the client application. |
Sources: [OAuthGrant.java:13-33](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrant.java#L13-L33)
Data Relationships
The relationship between the grant and the client metadata is captured in the following class diagram:
This diagram visualizes how the SDK organizes API responses into nested Java objects.
Sources: [OAuthGrant.java:10-109](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrant.java#L10-L109), [OAuthGrantClient.java:8-48](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrantClient.java#L8-L48), [ListOAuthGrantsResponseSuccess.java:10-60](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/ListOAuthGrantsResponseSuccess.java#L10-L60)
Revocation Logic
When you revoke a grant, the SDK sends a DELETE request to the specific grant endpoint. A successful revocation returns details about the event, including the revocation time and reason.
// Example Revocation Execution
RevokeOAuthGrantResponseSuccess res = oauthGrants.revoke("650e8400-e29b-41d4-a716-446655440001");
If the API returns an error (e.g., 404 for a non-existent grant), the service throws a ResendException containing the API error name and message.
Sources: [OAuthGrants.java:65-67](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrants.java#L65-L67), [OAuthGrantsTest.java:115-131](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrantsTest.java#L115-L131), [RevokeOAuthGrantResponseSuccess.java:8-66](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/RevokeOAuthGrantResponseSuccess.java#L8-L66)
Pagination
The listing operation supports pagination through ListParams. If hasMore is true in the ListOAuthGrantsResponseSuccess object, additional records are available in the API.
Sources: [ListOAuthGrantsResponseSuccess.java:51-53](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/ListOAuthGrantsResponseSuccess.java#L51-L53), [OAuthGrants.java:52-55](https://github.com/resend/resend-java/blob/e9f7a67ac16fafbe9b0c449b602d73505d4f4bad/OAuthGrants.java#L52-L55)
Summary
The OAuth Grants module provides a structured way to audit and control external access to a Resend team. By utilizing the OAuthGrants service, developers can list all permissions granted to third-party clients and programmatically revoke access when it is no longer required.