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

feat: add apple provider #328

Merged
merged 1 commit into from
Jan 27, 2025
Merged

Conversation

GreenmeisterDavid
Copy link
Contributor

As I needed the Apple provider in my own project, I figured I'd try and contribute to this awesome package and ecosystem. Feedback/changes to this PR welcome! 💚

Some things to note:

  • Apple will only provide user details the first time a user logs in. Thus, defineOAuthAppleEventHandler will only return the user once for each user. The tokens are always returned (and include a unique sub for each user which can be used to match with user info stored before).
  • I added Jose as a dependency to sign and verify JWTs, as it has no dependencies and works in all environments.
  • Apple returns a form POST instead of a query in the URL after user login. Therefore, implementations of defineOAuthAppleEventHandler, like in /playground/server/routes/auth/apple.ts, should NOT have the .get.ts suffix, as the handler will handle both POST and GET requests.

How to test:

  1. In Apple's developer platform, create:

    • An AppID,
    • A ServiceID,
    • A KeyID and Key (set full key in env, linebreaks must be replaced with \n)
    • And you need to copy your TeamID from here

    (I found this guide helpful.)

  2. Add these credentials to your .env file and use the defineOAuthAppleEventHandler. Remember not to use .get.ts-suffix to the auth route, as Apple will POST. Just naming it apple.ts will work).

For testing/development:
I found it useful to temporarily set
https://redirectmeto.com/http://localhost:3000/auth/apple
as a custom redirect URL, as Apple doesn't accept localhost directly.

  • If you do this, make sure to temporarily add it to your Apple Service ID redirect URLs.

Credits:

Code inspired by acidjazz's custom solution mentioned in #194.


Closes #187

@acidjazz
Copy link
Contributor

nice work!

Copy link

pkg-pr-new bot commented Jan 27, 2025

Open in Stackblitz

npm i https://pkg.pr.new/atinux/nuxt-auth-utils@328

commit: c466411

@atinux atinux merged commit 4e9e5a9 into atinux:main Jan 27, 2025
4 checks passed
@atinux
Copy link
Owner

atinux commented Jan 27, 2025

Thank you so much ❤️

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.

Apple Provider
3 participants