Android getToken in non-activity classes.
Hi, In my use case, I'm trying to request to an API hosted on cloudflare worker in an Android background service. My plan is to use the getToken method to get the JWT, and the worker will verify the JWT, once its verified the worker will perform some task and return the result.
However, I found that an AppCompatActivity is required to initialize the SDK, which is not possible to obtain in a background task. Thus I can't use the SDK nor get the JWT in non-activity classes. Is there an official way to mitigate this issue?
I read the source code of the SDK. It seems like only the login and logout tasks requires an actual Activity. The rest of them including getToken() should work with a Context instance, which is quite easy to obtain in background tasks. If you guys are OK, I can submit a pull request to improve this π Thanks in advance!
1 Reply
Hi Sean,
Thank you for your inquiry. To address this, consider performing the initialization in an Activity or Service with access to the necessary context, then passing the required tokens or data to your background service.
If the SDK's license permits, you might consider contributing a pull request to modify the getToken() method to accept a Context instance, enhancing its flexibility.
For more information, please refer to the Kinde Android SDK documentation:
https://docs.kinde.com/developer-tools/sdks/native/android-sdk
I hope this helps. Please let me know if you have further questions