From 7d8ecd790397e49c311b34325f56c7004c73ff35 Mon Sep 17 00:00:00 2001 From: Dmitry Popov Date: Fri, 4 Oct 2019 15:13:01 +0300 Subject: [PATCH] v1.0.0 --- PassKitHelper/PassKitHelper.csproj | 6 +-- README.md | 69 ++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/PassKitHelper/PassKitHelper.csproj b/PassKitHelper/PassKitHelper.csproj index d6e156b..075b965 100644 --- a/PassKitHelper/PassKitHelper.csproj +++ b/PassKitHelper/PassKitHelper.csproj @@ -12,11 +12,11 @@ git https://github.com/justdmitry/PassKitHelper https://github.com/justdmitry/PassKitHelper.git - 1.0.0-alpha2 + 1.0.0 Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs: create passes, sign pass packages, receive webhooks into your aspnetcore app. Apple Developer Account required! - apple passkit passbook pass + apple passkit passbook pass webservice true - New: `PassKitMiddleware` and `IPassKitService` to easily build your webservice for passes communications. + New: `PassKitMiddleware` and `IPassKitService` to easily build your webservice to comminucate with Apple server. diff --git a/README.md b/README.md index 9e05322..295001d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,25 @@ # PassKit Helper -Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs: create passes, sign pass packages. +Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs: create passes, sign pass packages, receive [de]install notifications and send pass updates. -**Attention:** Apple Developer Account required to create passes. +**Attention:** Apple Developer Account required! [![NuGet](https://img.shields.io/nuget/v/PassKitHelper.svg?maxAge=86400&style=flat)](https://www.nuget.org/packages/PassKitHelper/) -## Sample usage +## Features + +1. Create pass packages (`*.pkpass` files): + * With Fluent-styled `PassInfoBuilder` and `PassPackageBuilder` + * Using `byte[]` and/or `Stream` as content images + * Using `byte[]` or `Stream` or `X509Certificate2` as certificates + * Receive `MemoryStream` as result (save it to file or write to HttpResponse) +2. Receive notifications from Apple about pass [de]installations and send updates: + * Add `UsePassKitMiddleware` into your `Startup.Configure()` + * Implement `IPassKitService` for real processing. + +## Samples + +### 1. Creating pass package file ```csharp JObject pass = new PassInfoBuilder() @@ -35,6 +48,7 @@ JObject pass = new PassInfoBuilder() var appleBytes = await File.ReadAllBytesAsync("AppleWWDRCA.cer"); var passBytes = await File.ReadAllBytesAsync("pass.pfx"); +var passPfxPassword = "password-to-your-pfx-file"; MemoryStream package = await new PassPackageBuilder(pass) .Icon(await File.ReadAllBytesAsync("images/icon.png")) @@ -51,12 +65,61 @@ Code above will create this beautiful pass: ![](sample_pass.jpg) +### 2. Implementing WebService for interaction + +#### 2.1. Implement IPassKitService + +```csharp +public class PassKitService : IPassKitService +{ + public Task RegisterDeviceAsync(…) {…} + + public Task UnregisterDeviceAsync(…) {…} + + public Task<(int status, string[]? passes, string? tag)> GetAssociatedPassesAsync(…) {…} + + public Task<(int statusCode, MemoryStream? passData)> GetPassAsync(…) {…} + + public Task ProcessLogsAsync(…) {…} +} +``` + +#### 2.2. Register in `Startup` + +```csharp +public void ConfigureServices(IServiceCollection services) +{ + ... + services.AddSingleton(); +} + +public void Configure(IApplicationBuilder app) +{ + ... + app.UsePassKitMiddleware("/callbacks/passkit"); + ... +} +``` + + +Done! Now you can add `WebService` section when building your pass: +```csharp +var pass = new PassInfoBuilder() + ... + .WebService + .AuthenticationToken(someAuthenticationToken) + .WebServiceURL("https://example.com/callbacks/passkit") +``` + ## Installation Use NuGet package [PassKitHelper](https://www.nuget.org/packages/PassKitHelper/) ## Dependencies +* Microsoft.AspNetCore.Http.Abstractions, v2.1.1 +* Microsoft.Extensions.DependencyInjection.Abstractions, v2.1.1 +* Microsoft.Extensions.Logging.Abstractions, v2.1.1 * Newtonsoft.Json, v12.0.2 * System.Security.Cryptography.Pkcs, v4.6.0