program to fetch the api token of a user in a connect app?

Harshit Somani March 24, 2021

I am trying to make a connect app.In the app I'll need the api token of the user to add some information to user's(user is the one who installed the app)jira instance.My connect app should fetch user's api token.Can anyone please tell me how can I add a program which fetches users api-token

2 answers

0 votes
Caterina Curti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2021

@Harshit Somani When using ACE (https://developer.atlassian.com/cloud/confluence/getting-set-up-with-ace/), there are also options that are also options that are much more straightforward.

They are documented in the https://bitbucket.org/atlassian/atlassian-connect-express/ Read.me file in the How to send a signed outbound HTTP request back to the host paragraph.

This is how it is currently documented:
image.png

 

Cheers,
Caterina

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2021

Hello @Harshit Somani ,

It is not clear why you would need the user API Token in order to add some information about the user in the instance. Can you please clarify?

I am asking because in a connect app you can just impersonate the user and do whatever change on behalf the user:

User impersonation for Connect apps

Atlassian Connect supports user impersonation via the JWT Bearer token authorization grant type for OAuth 2.0. This authorization method allows apps with the appropriate scope (ACT_AS_USER) to access resources and perform actions in Jira and Confluence on behalf of users.

 

For further details on this please see:

 

Finally, for the future, please notice that this is not the best place to get help on development  related questions. The right resources are listed in https://developer.atlassian.com/resources. 

Specifically:

 

Cheers,
Dario

Harshit Somani March 29, 2021

@Dario B  
As shown in this link https://developer.atlassian.com/cloud/assetsapi/rest/api-group-assets/#api-asset-get,
I am trying to add assets to jira instance,If I use the same python code shown in that link,

response = requests.request( "GET",

url,

headers=headers )


we'll get an error which says 

{"errorMessage":"Request must be made by an active logged in user"}.

In order to recctify this error we can change the code as

response = requests.request( "GET",

url,

headers=headers ,

auth=('harshitsomani26@gmail.com','ZBI78xxxxxxxxxxxxxxx'))


So in order to do a PUT or GET request we need the user mail and api token of the jira instance,So I want to retrivee mail id and api token and store them in variables and use those varaibles in my python code,so that any user need not enter his user credentials when trying to run this program

 

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 30, 2021

Hello @Harshit Somani ,

As already mentioned, if you are building a connect add-on then you don't need any API Token since connect add-on use a different way to authenticate and impersonate users ( see Security for Connect apps and User impersonation for Connect apps for details).

 

Once this has been said, please notice that:

  • The code snippet from the page you are referring to is just an example and it is not taking authentication/authorization into account. Having implemented security for your connect app (JWT) then this should work with no need of any API Token. 
  • Saving the API Tokens of all the users in your site into an external app could pose a security risk.
  • If you are still convinced you want to proceed your way, there is a REST API endpoint to get all the users API Tokens available, but it only works with managed users.For details see: https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-users/#api-users-accountid-manage-api-tokens-get

 

I hope this helps.

 

Cheers,
Dario

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events