swift-server-community / APNSwift

📱HTTP/2 Apple Push Notification Service built with swift - send push notifications to iOS, iPadOS, tvOS, macOS, watchOS, visionOS, and Safari!
Apache License 2.0
693 stars 105 forks source link

TLS authentication is not working #208

Closed hakarim740-com-ra closed 1 month ago

hakarim740-com-ra commented 2 months ago

Describe the bug When using tls authentication method I receive MissingProviderToken error.

Expected behavior The push is supposed to be sent successfully.

Screenshots If applicable, add screenshots to help explain your problem.

Platform:

Platform:

kylebrowning commented 1 month ago

Can you share your config?

hakarim740-com-ra commented 1 month ago

Can you share your config?

let apnsConfig = APNSClientConfiguration(
    authenticationMethod: .tls(
        privateKey: .file(".../voip_apns_key.p12.pem"),
        certificateChain: [ ]),
    environment: .development
)
kylebrowning commented 1 month ago

.file isn't something supported by APNS, can you share that part of your code?

hakarim740-com-ra commented 1 month ago

.file isn't something supported by APNS, can you share that part of your code?

It is available in NIOSSLCertificateSource enum

kylebrowning commented 1 month ago

Gotcha, I just tried this and it worked for me, I had to make my own group though to get it to work.

        let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
        let client = APNSClient(
            configuration: .init(
                authenticationMethod: .tls(
                    privateKey: .privateKey(try! .init(file: "/Users/kyle/Developer/Certificates.pem", format: .pem)),
                    certificateChain: [
                        .certificate(try! .init(file: "/Users/kyle/Developer/Certificates.pem", format: .pem))
                    ]
                ),
                environment: .development
            ),
            eventLoopGroupProvider: .shared(group),
            responseDecoder: JSONDecoder(),
            requestEncoder: JSONEncoder()
        )
hakarim740-com-ra commented 1 month ago

Gotcha, I just tried this and it worked for me, I had to make my own group though to get it to work.

        let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
        let client = APNSClient(
            configuration: .init(
                authenticationMethod: .tls(
                    privateKey: .privateKey(try! .init(file: "/Users/kyle/Developer/Certificates.pem", format: .pem)),
                    certificateChain: [
                        .certificate(try! .init(file: "/Users/kyle/Developer/Certificates.pem", format: .pem))
                    ]
                ),
                environment: .development
            ),
            eventLoopGroupProvider: .shared(group),
            responseDecoder: JSONDecoder(),
            requestEncoder: JSONEncoder()
        )

Providing the certificateChain solved it for me.

Thanks.