TLS example? #194
-
| I just tried setting up a quick TLS-auth-based test, looking like this, and I get a run-time error: "Fatal error: TLSConfiguration.privateKey is not supported. You can still use this configuration option on macOS if you initialize HTTPClient with a MultiThreadedEventLoopGroup. Please note that using MultiThreadedEventLoopGroup will make AsyncHTTPClient use NIO on BSD Sockets and not Network.framework (which is the preferred platform networking stack)." I'm developing this on macOS but it will deploy on Linux. func testSimplePush() async throws { let client = APNSClient( configuration: .init( authenticationMethod: .tls( privateKey: .file("../Certs/Certificates.p12"), certificateChain: [] ), environment: .sandbox ), eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), byteBufferAllocator: .init() ) defer { client.shutdown { _ in Self.logger.error("Failed to shutdown APNSClient") } } struct Payload: Codable {} try await client.sendAlertNotification( .init( alert: .init( title: .raw("Simple Alert"), subtitle: .raw("Subtitle"), body: .raw("Body"), launchImage: nil ), expiration: .immediately, priority: .immediately, topic: "com.app.bundle", payload: Payload() ), deviceToken: "device-token"//, // deadline: .nanoseconds(Int64.max), // logger: Self.logger ) } |
Beta Was this translation helpful? Give feedback.
Answered by JetForMe Mar 1, 2024
Replies: 1 comment
-
| Thanks to @gwynne in the Vapor Discord, I've put together this working sample… import APNS import Foundation import Logging import NIOSSL … func testSimplePush() async throws { // Find your private key & cert file, exported from Keychain as .p12… let certs = URL(fileURLWithPath: #filePath, isDirectory: false) .deletingLastPathComponent() .deletingLastPathComponent() .deletingLastPathComponent() .deletingLastPathComponent() .appendingPathComponent("Certs") .appendingPathComponent("Certificates.p12") Self.logger.info("Certs: \(certs.path)") let certBundle = try NIOSSLPKCS12Bundle(file: certs.path) let client = APNSClient( configuration: .init( authenticationMethod: .tls( privateKey: .privateKey(certBundle.privateKey), certificateChain: certBundle.certificateChain.map { .certificate($0) } ), environment: .sandbox ), eventLoopGroupProvider: .shared(MultiThreadedEventLoopGroup.singleton), responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), byteBufferAllocator: .init() ) defer { client.shutdown { inError in if let error = inError { Self.logger.error("Failed to shutdown APNSClient: \(String(describing: error))") } } } struct Payload: Codable {} try await client.sendAlertNotification( .init( alert: .init( title: .raw("Simple Alert"), subtitle: .raw("Subtitle"), body: .raw("Body"), launchImage: nil ), expiration: .none, priority: .immediately, topic: "<your app’s bundle ID>", payload: Payload() ), deviceToken: "<32 hex bytes>" ) } static let logger = Logger(label: "Tests") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by JetForMe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Thanks to @gwynne in the Vapor Discord, I've put together this working sample…