How to manage Oauth access token in android and its flow between activities? -
i have built rest api using rails , doorkeeper. i'm using assertion grant flow , facebook login create , login user in android client.
i've logged in , got access token server using retrofit. access token has token, refresh_token, token_type, expires_in , created_at info.
i have following option manage , maintain token while user browsing android app.
- save info access token in sharedpreferences when user opens app , logs in. , leads main activity on successful login, access shared preferences , access api using token.
- second option is, pass access token object parcelable object , access_token in next activity using object.
i can check if access_token expired comparing current time , created_at time. everytime before accessing api. if expire, access new token using refresh_token.
i think both of above approaches leads code duplication , repeating same thing.
- if there other approach it, that'll great well. think it'd great if retrofit client can manage whether token expired or not , if expire, should request new token. in short i'm thinking of using sort of interceptor. don't how it.
which of above approach more suitable.
thanks!
you should store data in singleton after login can access anywhere in app.
then can if use okhttp retrofit can use okhttp's interceptor described in this post refresh token when expired.
Comments
Post a Comment