Apple App Store Server Rust Library
The Rust server library for the App Store Server API, App Store Server Notifications, the Retention Messaging API, and Advanced Commerce API.
Requirements
- Rust 1.65.0 or later
Installation
Specify app-store-server-library in your project's Cargo.toml file, under the [dependencies] section:
[]
= { = "4.1.1", = ["receipt-utility", "api-client", "ocsp"] }
Feature Flags
api-client- Enables the App Store Server/Advanced Commerce API client functionalityreceipt-utility- Enables receipt processing and transaction ID extractionocsp- Enables OCSP (Online Certificate Status Protocol) verification
Check crates.io for the latest version number.
Obtaining an In-App Purchase key from App Store Connect
To use the App Store Server API or create promotional offer signatures, a signing key downloaded from App Store Connect is required. To obtain this key, you must have the Admin role. Go to Users and Access > Integrations > In-App Purchase. Here you can create and manage keys, as well as find your Issuer ID. When using a key, you'll need the Key ID and the Issuer ID as well.
Obtaining Apple Root Certificates
Download and store the root certificates found in the Apple Root Certificates section of the Apple PKI site. Provide these certificates as an array to a SignedDataVerifier to allow verifying the signed data comes from Apple.
Usage
API Usage
App Store Server API
use ;
async
Advanced Commerce Server API
// NOTE: .unwrap() used for example purposes only
use ;
async
Verification Usage
// NOTE: .unwrap() used for example purposes only
let root_cert = "apple-root-cert-in-base-base64-format"; // https://www.apple.com/certificateauthority/AppleRootCA-G3.cer
let root_cert_der = root_cert.as_der_bytes.unwrap; // Use `base64` crate to decode base64 string into bytes
let verifier = new;
let payload = "signed-payload";
let decoded_payload = verifier.verify_and_decode_notification.unwrap;
OCSP Verification
When the ocsp feature is enabled, the library will automatically perform OCSP (Online Certificate Status Protocol) checks to verify that certificates haven't been revoked. This provides an additional layer of security by checking certificate validity in real-time with Apple's OCSP responders.
To enable OCSP verification:
[]
= { = "4.1.1", = ["ocsp"] }
OCSP verification is performed automatically when verifying signed data.
Note: OCSP request is blocking, not async.
Async signed data verification is coming soon.
Receipt Usage
let receipt = "MI..";
let transaction_id = extract_transaction_id_from_app_receipt;
Note: To extract transaction id from app/tx receipt,
receipt-utilityfeature must be enabled.
Promotional Offer Signature Creation
V1 Signature Creation
// NOTE: .unwrap() used for example purposes only
use PromotionalOfferSignatureCreator;
let private_key = include_str!;
let creator = new.unwrap;
let nonce = new_v4;
let timestamp = now.timestamp_millis;
let signature: String = creator.create_signature.unwrap;
V2 Signature Creation
// NOTE: .unwrap() used for example purposes only
use PromotionalOfferV2SignatureCreator;
let private_key = include_str!;
let creator = new.unwrap;
let signature: String = creator.create_signature.unwrap;
Advanced Commerce Signature Creation
Prepare request object:
- Receive request object from the client.
- Or create request from the server side.
Supported request objects: OneTimeChargeCreateRequest, SubscriptionCreateRequest, SubscriptionModifyInAppRequest or SubscriptionReactivateInAppRequest.
// NOTE: .unwrap() used for example purposes only
use PromotionalOfferV2SignatureCreator;
let request_object = ... // Receive from client side or create on server side
let private_key = include_str!;
let creator = new.unwrap;
let signature: String = creator.create_signature.unwrap;
Documentation
- The full documentation is available at docs.rs
- App Store Server API Documentation
- App Store Server Notifications Documentation
- Retention Messaging API Documentation
- Advanced Commerce API Documentation
- WWDC Video