I am creating two apps. The main app has included a login, where a custom account is created. With the second app I want to access the user data (refresh token is stored there) from the main app.
The main app is creating a custom account and the refresh token is stored via setUserData. Through the main app it is no problem to get the refresh token with
mAccountManager.getUserData(account, KEY_REFRESH_TOKEN);
It works perfectly fine to retrieve the refresh token, if the both apps are signed with the same key.
But when I call this method and the apps are not signed with the same key:
mAccountManager.getUserData(account, KEY_REFRESH_TOKEN);
I receive following error:
2019-10-01 12:01:51.143 5528-5528/at.exampleapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: at.exampleapp, PID: 5528
java.lang.SecurityException: uid 10265 cannot get user data for accounts of type: accountType
at android.os.Parcel.createException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1918)
at android.os.Parcel.readException(Parcel.java:1868)
at android.accounts.IAccountManager$Stub$Proxy.getUserData(IAccountManager.java:1020)
at android.accounts.AccountManager.getUserData(AccountManager.java:515)
at eu.aal.dapas.component_auth.AccountAuthenticator.getExistingAccountRefreshToken(AccountAuthenticator.java:206)
at eu.aal.dapas.component_auth.AccountAuthenticator.refreshAccessToken(AccountAuthenticator.java:138)
at eu.aal.dapas.component_auth.DapasAccountManager.getAccessToken(DapasAccountManager.java:41)
at at.e_nnovation.emma.apps.exampleapp.MainActivity.getUserDetails(MainActivity.java:196)
at at.e_nnovation.emma.apps.exampleapp.MainActivity$1.onClick(MainActivity.java:53)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.accounts.AccountManagerService.getUserData(AccountManagerService.java:1574)
at android.accounts.IAccountManager$Stub.onTransact(IAccountManager.java:77)
at com.android.server.accounts.AccountManagerService.onTransact(AccountManagerService.java:1100)
at android.os.Binder.execTransact(Binder.java:735)
So my questions are:
1.) Is it possible at all to call the user data from a custom account with accountManager.getUserData(account, key) from another app?
2.) If not is there a way to get the refresh token from the custom account?
As you can see in the documentation:
This method requires the caller to have a signature match with the authenticator that owns the specified account.
So you need to have both apps signed with the same key.
Or you can just use getAuthToken
and invalidateAuthToken
in the second app and implement authenticator service in the first one. Just follow this documentation