Back

How should I "refresh session" when using Custom Tokens

  • 0
  • Self Hosted
  • Auth
  • Apple
Rando
6 Apr, 2024, 17:46

I'm trying to use custom tokens for authenticating a user that uses AppleSignIn in an iOS app.

I don't like the OAuth2 implementation for Apple because it kicks the user out of my app, loads Safari to present the authentication screen, then prompts the user "Do you want to open "MyAppName"?" after authentication before finally returning them to my app - which is much, much less than ideal for the user experience.

So to avoid that, I'm handling the AppleSignIn within the app then sending the identityToken to an appwrite function that validates it, then creates an Appwrite user account and generates a custom token (with a 5 minute expiry) that gets returned to the app.

The app exchanges the custom token for a session with: Accounts.createSession(userId: secret:)

That all works - but the providerRefreshToken value is blank and I'm unsure of how to handle refreshing the session.

What is the recommended way to refresh an Appwrite session that was created using a custom token?

TL;DR
Developers are using custom tokens for user authentication with AppleSignIn in an iOS app to avoid a poor user experience caused by OAuth2 implementation. The issue is on how to refresh an Appwrite session that was created using a custom token. Potential Solution: To refresh the session when using custom tokens with Appwrite, developers can schedule a task to periodically generate a new custom token before the expiry time is reached. This can be done by creating a new custom token and exchanging it for a new session using the Accounts.createSession(userId: secret:) function.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more