1

I have a web app which uses the Xero.NetStandard.OAuth2Client package to allow for authentication with Xero.

Once the user is redirected back into my app, I use the IXeroClient.RequestAccessTokenAsync method to exchange their code for an IXeroToken object, which allows me to make calls against the Xero API, as expected.

The one thing I do not know how to do, and which I can't seem to find in the official documentation, is how do I extract the user's details (namely their name and email address) from the IXeroToken object.

As per the standard, the information is encoded as JWT string in the IdToken property, but I am not sure how I am meant to get the information out of it without an additional dependency.

Itamaram
  • 719
  • 7
  • 17

1 Answers1

2

The built in System.IdentityModel.Tokens.Jwt.JwtSecurityToken class can deserialize the IdToken payload.

new JwtSecurityToken(accessToken.IdToken).Claims contains all the claims in the token.

The relevant types are:

  • email - The user's email
  • xero_userid - The user's id (guid)
  • given_name - The user's first name
  • family_name - The user's last name

The claims' existence is obviously conditional to the appropriate scope being set.

Itamaram
  • 719
  • 7
  • 17