6

I'm trying to write a Tasker script for my (rooted) phone that uses the same Google credentials that are being used on my device (for Gmail, Drive, etc.).

Where can I find Google's OAuth (or other) authentication tokens on my device?

I checked inside /data/data/com.google.android.gms/databases but couldn't find anything I could recognize as an authentication token.

1 Answer 1

10

The authentication token for Google accounts and of other accounts which uses AccountManager class are stored inside:

/data/system/users/0/accounts.db   # for Android Marshmallow and earlier
/data/system_ce/0/accounts_ce.db   # for Android Nougat and above.

0 implies primary user of the device. If you have secondary user accounts, replace 0 with the user id of that account. To find out the user id follow my answer here.

Note that access to that database requires root access.

4
  • 4
    For anyone else interested: Here's a command that will get you a token that has access to both Gmail and Google Drive (you need sqlite3): su -c 'uid="$(/system/bin/readlink -f /storage/self/primary | /system/bin/grep -E -o "[0-9]+")"; "${PREFIX}/bin/sqlite3" -readonly "/data/system_ce/${uid-0}/accounts_ce.db" '"\"SELECT authtoken FROM authtokens WHERE type LIKE 'com.google.android.gm:%:oauth2:%https://mail.google.com/ %https://www.googleapis.com/auth/drive %' ORDER BY _id DESC LIMIT 1;\""
    – user541686
    Sep 21, 2019 at 23:15
  • @Mehrdad $uid will always be 0 if su switches to root mount namesapce, depends on configuration in root manager app. Also debug builds (most custom ROMs) already have /system/bin/sqlite3. Sep 22, 2019 at 0:02
  • 1
    @IrfanLatif: Oh I see. I actually realized /system/bin/readlink -f /storage/self/primary | /system/bin/grep -E -o \"[0-9]+\" is faster so that's what I'm doing now. Sadly my ROM doesn't have sqlite3 so that one's not an option for me, but thanks!
    – user541686
    Sep 22, 2019 at 0:05
  • @Mehrdad if you are using Magisk you can download the sqlite module to get access to sqlite3 binary.
    – Firelord
    Sep 22, 2019 at 0:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .