Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite: APNs: Scoped App Tokens #101

Merged
merged 19 commits into from
May 19, 2024
Merged

Rewrite: APNs: Scoped App Tokens #101

merged 19 commits into from
May 19, 2024

Conversation

JJTech0130
Copy link
Owner

@JJTech0130 JJTech0130 commented May 18, 2024

Allows receiving notifications sent from the public APNs API

  • ACK incoming notifications
  • Set sleep power state/active interval
  • Automatically filter topics
  • Keep track of scoped tokens internally
  • Rework await connected API
  • Embed personal key for sending test notifications in tests
  • Add CLI tool

@JJTech0130 JJTech0130 linked an issue May 18, 2024 that may be closed by this pull request
@JJTech0130
Copy link
Owner Author

Note to self: the current receive API relies on the fact that the network is slower to respond than the scheduler is to schedule the receive task, as there is no backlog.
Not necessarily an incorrect assumption, but should be noted.

@JJTech0130
Copy link
Owner Author

JJTech0130 commented May 19, 2024

The API is finished, it involved developing a new "Stream Filters" mechanism internally, but it leads to a nice clean test like this:

@pytest.mark.asyncio
async def test_scoped_token():
    async with apns.create_apns_connection(
        *await apns.activate(), courier="1-courier.sandbox.push.apple.com"
    ) as connection:

        token = await connection.mint_scoped_token("dev.jjtech.pypush.tests")

        test_message = f"test-message-{uuid.uuid4().hex}"

        # Not part of pypush, uses Apple's public APNs API
        await send_test_notification(token.hex(), test_message.encode())

        await connection.expect_notification(
            "dev.jjtech.pypush.tests",
            token,
            lambda c: c if c.payload == test_message.encode() else None,
        )

@JJTech0130
Copy link
Owner Author

JJTech0130 commented May 19, 2024

New notifications subcommand, for example:
pypush notifications dev.jjtech.pypush.tests --sandbox
Screenshot 2024-05-18 at 8 39 46 PM

Note that it currently does not provide any method of saving the certificate or tokens used.

You can test it out using your own CloudKit console if you have a Developer ID, or use the .pem file in the tests/assets/ directory and use it with any of the online APNs test websites.

pypush/apns/lifecycle.py Outdated Show resolved Hide resolved
pypush/apns/lifecycle.py Show resolved Hide resolved
pypush/apns/protocol.py Show resolved Hide resolved
pypush/apns/protocol.py Show resolved Hide resolved
pypush/cli/__init__.py Show resolved Hide resolved
makes awaiting _connected an implementation detail
@JJTech0130 JJTech0130 merged commit ce88a8e into main May 19, 2024
4 checks passed
@JJTech0130 JJTech0130 deleted the app-tokens branch May 19, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement receiving app push notifications
1 participant