I have an android app which talks witha Node.js backend, via REST api. We use OAuth token received from Google for authorization, and we have agreed on the flow in which I use the token in HTTP request everytime I make a request.
So, which is the best practice to store the token ? -
a) Store the token in SharedPreference, and use the same SharedPrefrence in the activity that makes the network calls.
OR
b) Store it using a POJO, and use getters and setters to retrieve and clear the token.
I have just started off with network related mini projects in Android. And hence this could be a very basic question. Any help is really appreciated.
Thanks
How are you retrieving the token or doing Authorization?
If you are using GoogleAuthUtil
or GoogleAccountCredential
API's, the persistance of token is automatically managed by API's themselves.
You should not be required to do it manually.
See this question on which one to use:
Access to Google API - GoogleAccountCredential.usingOAuth2 vs GoogleAuthUtil.getToken()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With