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” Prerequisites
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 dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Revoke grantawait client.grant.cancel({ accessToken: CONTINUE_ACCESS_TOKEN, url: CONTINUE_URI})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
Prerequisites View full source
// Import dependenciesuse open_payments::client::AuthenticatedResources;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_authenticated_client()?;
// Revoke grantlet 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?; Prerequisites View full source
// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Revoke grant$response = $opClient->grant()->cancel( [ 'access_token'=> $ACCESS_TOKEN, 'url' => $CONTINUE_URI ]); Prerequisites
package main
// Import dependenciesimport ( "context" "fmt" "log"
op "github.com/interledger/open-payments-go")
func main() { // Initialize client client, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID) if err != nil { log.Fatalf("Error creating authenticated client: %v\n", err) }
// Revoke grant if err := client.Grant.Cancel(context.TODO(), op.GrantCancelParams{ URL: CONTINUE_URI, AccessToken: CONTINUE_ACCESS_TOKEN, }); err != nil { log.Fatalf("Error revoking grant: %v\n", err) }
// Output fmt.Println("Grant revoked successfully")} Prerequisites
// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientvar client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Retrieve the walletsvar receiverWallet = client.getWalletAddress("https://cloudninebank.example.com/merchant");
// Create incoming paymentvar grantRequest = this.client.createGrantIncomingPayment(receiverWallet);
// Revoke grantthis.client.createGrantCancel(grantRequest);
// Outputlog.info("CANCELLED: {}", grantRequest);