Why is AccountAuthenticator#getAuthToken() not called?

后端 未结 2 999
故里飘歌
故里飘歌 2020-12-31 10:53

I created my own Android account authenticator by extending AbstractAccountAuthenticator and implementing addAccount() and getAuthToken(). Some of the methods in it are call

2条回答
  •  一整个雨季
    2020-12-31 11:11

    Your comment cleared things up immensely -- if you set the auth token for the account, then your getAuthToken method will not be called until the token is invalidated. You generally do this by calling invalidateAuthToken upon receiving a 401 or 403 or what have you from the web service.

    From the Javadoc for the getAuthToken methods:

    If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, the user is prompted to enter a password.

    Since your token is in the cache, it is returned directly and your authenticator is not consulted.

提交回复
热议问题