Revoke a grant request
If an authorized client no longer needs access to protected resources, the client can revoke the corresponding grant request.
These code snippets enable a client to revoke (cancel) a grant that it was previously issued. When a grant request is revoked, the request is placed into a finalized state and no further updates to the grant are allowed.
Before you begin
Section titled “Before you begin”We recommend creating a wallet account on the test wallet. Creating an account allows you to test your client against the Open Payments APIs by using an ILP-enabled wallet funded with play money.
Revoke a grant request
Section titled “Revoke a grant request”Initial configuration
If you’re using JavaScript, only do the first step.
- Add
"type": "module"topackage.json. - Add the following to
tsconfig.json{"compilerOptions": {"target": "ES2022","module": "ES2022"}}
Import dependencies
import { createAuthenticatedClient } from "@interledger/open-payments"; Copied! Initialize Open Payments client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID,
}); Copied! Revoke grant
await client.grant.cancel({
accessToken: CONTINUE_ACCESS_TOKEN,
url: CONTINUE_URI,
}); Copied! For TypeScript, run tsx path/to/directory/index.ts. View full TS source
For JavaScript, run node path/to/directory/index.js. View full JS source
Import dependencies
use open_payments::client::AuthenticatedResources;
use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; Copied! Initialize Open Payments client
let client = create_authenticated_client()?; Copied! Revoke grant
let access_token = get_env_var("CONTINUE_ACCESS_TOKEN")?;
let continue_uri = get_env_var("CONTINUE_URI")?;
client
.grant()
.cancel(&continue_uri, Some(&access_token))
.await?; Copied! Import dependencies
use OpenPayments\AuthClient;
use OpenPayments\Config\Config; Copied! Initialize Open Payments client
$config = new Config($WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);
$opClient = new AuthClient($config); Copied! Revoke grant
$response = $opClient->grant()->cancel([
"access_token" => $ACCESS_TOKEN,
"url" => $CONTINUE_URI,
]); Copied! // 1. Import:import org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// 2. Client instance using HTTP:IOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient( "WalletAddress", "PrivateKeyPEM", "KeyId");
// 3. Retrieve the wallets:var senderWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");var receiverWallet = client.getWalletAddress("https://cloudninebank.example.com/merchant");
// 4. Create incoming payment:var grantRequest = this.client.createGrantIncomingPayment(receiverWallet);var incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// 5. Create quote:var quoteRequest = this.client.createGrantQuote(senderWallet);var quote = this.client.createQuote(quoteRequest.getAccess().getToken(), senderWallet, incomingPayment);
var urlToOpen = "http://localhost:%d?paymentId=1234".formatted(port);
// 6. Create outing payment from quote:var opContinueInteract = this.client.createGrantContinuation( senderWallet, quote.getDebitAmount(), URI.create(urlToOpen), "test");
// 7. USER APPROVES REQUEST.
// 8. Finalize/Continuevar finalized = this.client.createGrantFinalize(opContinueInteract, "Reference from USER interaction.");
// 9. TODO: Revoke the finalised grant.
// 10. Logging:log.info("FINALIZED: {}", finalized);