How to get personal token id list along with username, email address and user key using Database query
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
Database query to get a list of users with details such as username, email address and user key along with token id for users.
Solution
Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
Below query will get you username, email address, user key and token id for all the users
⚠️ Below query has been tested with postgreSQL , MySQL and Oracle:
PostgreSQL
1
2
3
SELECT CU.USER_NAME ,CU.EMAIL_ADDRESS ,UM.USER_KEY , AFPT."TOKEN_ID"
FROM CWD_USER CU ,USER_MAPPING UM,"AO_81F455_PERSONAL_TOKEN" AFPT
WHERE CU.USER_NAME =UM.USERNAME AND UM.USER_KEY = AFPT."USER_KEY";
Oracle
1
2
3
SELECT CU.USER_NAME ,CU.EMAIL_ADDRESS ,UM.USER_KEY , AFPT."TOKEN_ID"
FROM CWD_USER CU ,USER_MAPPING UM,"AO_81F455_PERSONAL_TOKEN" AFPT
WHERE CU.USER_NAME =UM.USERNAME AND UM.USER_KEY = AFPT."USER_KEY";
MySQL
1
2
3
SELECT CU.USER_NAME ,CU.EMAIL_ADDRESS ,UM.USER_KEY , AFPT.TOKEN_ID
FROM cwd_user CU ,user_mapping UM,AO_81F455_PERSONAL_TOKEN AFPT
WHERE CU.USER_NAME =UM.USERNAME AND UM.USER_KEY = AFPT.USER_KEY;
We have one KB article on Confluence Data Model. , which will give you more details in case you wish to modify the above query - depending upon the requirement.
Info
Personal access tokens (PATs) are a secure way to use scripts and integrate external applications with your Atlassian application. If an external system is compromised, you simply revoke the token instead of changing the password and consequently changing it in all scripts and integrations.
Personal access tokens are a safe alternative to using username and password for authentication with various services
More details about Using Personal Access Tokens can be found in the document.
Was this helpful?