0

I am trying to use dmfs/oauth2-essentials for oauth2 in an application. The problem is the refresh token. I am able to store the token string and refresh token string in AccountManager. Refresh token using userdata bundle. User first logins with ResourceOwnerPasswordGrant and receives a token with refresh token.

The problem is that Bundle accepts just primitive things like strings to be stored. But the dmfs/oauth2-essentials require the OAuth2AccessToken object when using TokenRefreshGrant()

Is there a way to use the refresh token string directly? am I missing something?

Thanks!

Evren Yurtesen
  • 2,267
  • 1
  • 22
  • 40

1 Answers1

0

I don't know if you've solved your problem, but I'll write here my experience in case it's handy for somebody.

You can create an Account in android using AccountManager. You're right by storing AccessToken in the Account, but perhaps you haven't realised that you can store multiple tokens within an Account, just by typing different token type. That way, you can retrieve different tokens using peekAuthToken(Account account, String authTokenType) just by passing a different authTokenType String. Be careful not letting the user to retrieve a refreshToken outside your Authenticator in getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options), I do so by comparing authTokenType string.

joninx
  • 1,775
  • 6
  • 31
  • 59
  • 1
    I converted token to JSON and stored the whole thing as text. See my issue about this on dmfs GitHub -> https://github.com/dmfs/oauth2-essentials/issues/50 – Evren Yurtesen May 17 '18 at 11:33
  • Can you tell me how do you manage to update your access token? I mean, how do you get a new access token when the expiration happens, using your refresh token. Thanks! – joninx May 17 '18 at 12:32
  • With `dmfs/oauth2-essentials` it is possible to request a refresh with `OAuth2AccessToken` object. If you check its documentation you can see how it works. Then I store the new token object as string again for future use. I have an example on how I refresh the token in the issue report I linked in my first message. – Evren Yurtesen May 17 '18 at 12:38