Not able to get current logged in user account id

Hello,

I need current logged in user account id. So, I tried to call REST API “/rest/api/3/myself” to get current user from my connect application (written in asp.net core) for authentication I created JWT and it has following info:

iss:<my-connect-app-key>,
aud:<clientkey-saved-from-handshake>,
iat:<current-time>,
exp:<current-time+15minutes>,
qsh:<encoded-qsh> decoded-form=“GET&/rest/api/3/myself&”

I logged in with 2-3 different accounts to check into but every time I got same user info, the user info display name is showing my app name. Not sure what I’m doing wrong.

Thanks

Hello again @MikeDev. Thanks for your persistence in figuring out Atlassian Connect in ASP.NET.

The response you are getting is the expected response. Your app has a user, and when it creates a JWT, myself is the app. But I do understand what you are trying to do. There are 2 options:

Hi there @ibuchanan

Im still confused.

We get a response from Atlassian on install (/installed) in our connect app. We then need to supply the

“urn:atlassian:connect:useraccountid”

of the currently logged in user.

The issue is that the accountId is NOT sent in the POST to /installed.

So How do I get that accountId from the backend BEFORE getting the user accesstoken I need to make requests to the JIRA API?

OK - after struggling all day, I finally found out where to get the account id to add to the JWT to actually get the user access token in order to call the JIRA Api. its passed in the headers!!! (Nowhere in the docs did I find that). Its in the Authorization header key passed in at the /install call from Atlassian. So to get the account id, this is how you do it: (needs rewriting)

var stream = Request.Headers[“Authorization”].ToString().Replace("JWT ", string.Empty);
var handler = new JwtSecurityTokenHandler();
var jsonToken = handler.ReadToken(stream);
var tokenS = jsonToken as JwtSecurityToken;
var jti = tokenS.Claims.First(claim => claim.Type == “sub”).Value;