# Authentication works but cant use token in ESI call

**URL:** <https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409>\
**Category:** Third Party Developers\
**Created:** [October 13, 2021, 9:06pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409 "2021-10-13T21:06:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 13, 2021, 9:06pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/1 "2021-10-13T21:06:42Z")

</div>

Hi,

I’m returning to eve after a long pause and all my own tools are not working anymore so I thought I jump onto the swagger train as it’s a nice challenge.

I have gotten my authentication to work with the code challenge and all the jazz and I also successfully get the token and I can verify and grab the data in that token with no issue. Now I am trying to call my first ESI call. I’ve created implementations for a status call and a character skills call just to make sure I can do unauthorized calls to the ESI and authorized calls.

Server status call works great, so my implementation works fine on unauthorized calls, but when I try to authorized calls I get the same response no matter what I do:

{Method: GET, RequestUri: ‘[https://esi.evetech.net/latest/characters/726604936/skills/](https://esi.evetech.net/latest/characters/726604936/skills/)’, Version: 1.1, Content: , Headers:  
{  
Authorization: Bearer eyJhbGciOiJS…PpW8d4sqkMighoQ  
User-Agent: SissanyRavonsEveTools/0.1  
}

StatusCode: 403, ReasonPhrase: ‘Forbidden’, Version: 1.1  
{“error”:“authentication failure”}

My authorization grants to all scopes and I can see in the token that it has the ‘esi-skills.read\_skills.v1’ required for character skills. As far as I understand the Authorization token is just the access token you get when to complete the code challenge right? At least that is what I get from the ESI documentation: [Sending an authenticated request to ESI | esi-docs](https://docs.esi.evetech.net/docs/sso/sending_esi_auth_request.html)

Any suggestions?

---

<div class="post-metadata">

**Author:** ![BusError](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/buserror/32/306499_2.png) [@BusError](https://forums.eveonline.com/u/BusError)\
**Post date:** [October 14, 2021, 12:50am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/2 "2021-10-14T00:50:39Z")

</div>

does your JWT validate correctly against EVE’s public RSA key [listed in the jwks](https://login.eveonline.com/oauth/jwks)?

there are a lot of libs around that lets you do it, or you can verify it online with [https://jwt.io](https://jwt.io) if you revoke your token after writing it there / ready to accept the risk of a token leak

---

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 14, 2021, 5:23am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/3 "2021-10-14T05:23:02Z")

</div>

Thank you @BusError. I have forgotten that I have removed that step during some testing and never get around to it. Been trying to do it for a while now, but I am apparently not particularly strong in security algorithms. I fail to understand the link between the jwks information and how to use it to do the validation.

FYI, building a WCF .net core application, so if anyone has a good example of this, I would jump for joy.

---

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 14, 2021, 7:28am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/4 "2021-10-14T07:28:43Z")

</div>

With a lot of profanities and tea, I got the Validation part working. Reading [this readme](https://github.com/uruk-project/Jwt) and reading the [rfc7517](https://datatracker.ietf.org/doc/html/rfc7517) specifications got me on the right track. Of cause, it was very easy when I had all the parts. The problem on the ESI endpoint where Authentication is required is still an issue even with a validated token. I am right to assume that the validation is just to confirm the token is valid and does not change the token in any way?

I posted my validation code here if that helps:

> **Summary**
>
> ```auto
> public void ValidateCurrentToken(AccessInfo info)
> {
> var eveJwksJson = GetEveTokenSecurityKeyInfo();
> var tokenHandler = new JwtSecurityTokenHandler();
> var keyset = JsonWebKeySet.Create(eveJwksJson);
> 	
> var tokenParameters = new TokenValidationParameters();
> tokenParameters.ValidateIssuerSigningKey = true;
> tokenParameters.ValidateIssuer = true;
> tokenParameters.ValidateAudience = false;
> tokenParameters.ValidateLifetime = true;
> tokenParameters.ValidateActor = false;
> tokenParameters.ValidIssuers = new List<string>{ "https://login.eveonline.com", "login.eveonline.com" };
> tokenParameters.IssuerSigningKey = keyset.Keys.First();
> 
> SecurityToken validatedToken;
> try
> {
> tokenHandler.ValidateToken(info.AccessToken, tokenParameters, out validatedToken);
> }
> catch(Exception e)
> {
> throw new AuthenticationException("Token is not valid: " + e.Message);
> }
> 
> var securityToken = (JwtSecurityToken) validatedToken;
> info.CharacterId = Convert.ToInt32(securityToken.Subject.Replace("CHARACTER:EVE:", ""));
> info.Issued = securityToken.IssuedAt;
> info.ValidTo = securityToken.ValidTo;
> info.Scopes.AddRange(securityToken.Claims.Where(claim => claim.Type == "scp").Select(claim => claim.Value));
> 
> AccessInfo = info;
> SaveAccessInfo();
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Heritor\_Skoliya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/heritor_skoliya/32/388743_2.png) [@Heritor\_Skoliya](https://forums.eveonline.com/u/Heritor_Skoliya)\
**Post date:** [October 14, 2021, 9:11am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/5 "2021-10-14T09:11:08Z")

</div>

> [@Sissany\_Ravon](#):
>
> I am right to assume that the validation is just to confirm the token is valid and does not change the token in any way?

Yeah, it’s just for you — to make sure the token is valid. It does not affect the token itself. The only thing I notices, if you do not process token by a validation liibrary, you need to convert `info.AccessToken` to an object manually because it’s presented as a Base64 string. Validating libraries usually convert it under the hood, and you have a converted payload after using them.

---

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 14, 2021, 9:32am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/6 "2021-10-14T09:32:41Z")

</div>

So the access token mentioned in the ESI documentation about sending Esi Authenticated requests is not the value you get from the SSO, and I need to convert that JWT token into something else?

---

<div class="post-metadata">

**Author:** ![BusError](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/buserror/32/306499_2.png) [@BusError](https://forums.eveonline.com/u/BusError)\
**Post date:** [October 14, 2021, 9:33am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/7 "2021-10-14T09:33:33Z")

</div>

Ah .NET. Last I worked with it WIF was the way to do federated identity and Visual studio can just be pointed to a jwks url and it would generate most of the configs for you.

But nower days it looks like your best bet is with this provider [GitHub - aspnet-contrib/AspNet.Security.OAuth.Providers: OAuth 2.0 social authentication providers for ASP.NET Core](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers)

Apparently it already has support for eve

---

<div class="post-metadata">

**Author:** ![Heritor\_Skoliya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/heritor_skoliya/32/388743_2.png) [@Heritor\_Skoliya](https://forums.eveonline.com/u/Heritor_Skoliya)\
**Post date:** [October 14, 2021, 9:39am UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/8 "2021-10-14T09:39:01Z")

</div>

> [@Sissany\_Ravon](#):
>
> So the access token mentioned in the ESI documentation about sending Esi Authenticated requests is not the value you get from the SSO, and I need to convert that JWT token into something else?

Umm, it’s the same JWT, but it’s just not converted from Base64-encoded string to a plain object. As I remember, when I was implementing and debugging SSO on my website, manually decoded Base64 string and the same string processed with a validation library produced the same payload in result.

---

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 15, 2021, 6:16pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/9 "2021-10-15T18:16:55Z")

</div>

I’m beginning to wonder if I have missed something basic in the way I need to call the ESI. I failed multiple attempts on getting my code to work, so now I have tested it on Fiddler. If I can get it to work there, I can get it to work anywhere. But I can’t! it won’t work! If I sound frustrated at this point, that is because I am.

I can call /status/ end point without an issue:

```
GET https://esi.evetech.net/latest/status/ HTTP/1.1
Host: esi.evetech.net

HTTP/1.1 200 OK
Date: Fri, 15 Oct 2021 17:52:31 GMT
<other headers omitted>

{"players":24526,"server_version":"1952234","start_time":"2021-10-15T11:04:47Z"}

```

So no problem contacting esi. Then I try to get my characters skills, but without authorization:

```
GET https://esi.evetech.net/latest/characters/726604936/skills/ HTTP/1.1
Host: esi.evetech.net

HTTP/1.1 401 Unauthorized
Date: Fri, 15 Oct 2021 17:31:41 GMT
<headers omitted>

{"error":"authorization not provided"}	

```

This response makes perfect sense, as I haven’t added the token yet. So I authorize and get a fresh token to use, and add it to the request:

```
GET https://esi.evetech.net/latest/characters/726604936/skills/ HTTP/1.1
Host: esi.evetech.net
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkpXVC1TaWduYXR1cmUtS2V5IiwidHlwIjoiSldUIn0.eyJzY3AiOlsiZXNp...

HTTP/1.1 403 Forbidden
Date: Fri, 15 Oct 2021 18:09:03 GMT
<headers omitted>

{"error":"authentication failure"}

```

I am out of ideas at this point. THIS… should have worked. I have done EXACTLY as the documentation says or as any other forums or sources indicate. I have checked my client credentials and permissions and they are all set up to call this endpoint. My token is validated and has all the information that the ESI documentation says it has.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [October 15, 2021, 6:32pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/10 "2021-10-15T18:32:28Z")

</div>

Can you walk thru the steps you’re doing to get this token? E.g. using form data payloads, the V2 endpoints, etc?

I’ll bring this up on Slack.

EDIT: How many scopes does this token have? Did you try creating a token with just the one scope?

Ref: [Authorization failure when token is too long · Issue #1089 · esi/esi-issues · GitHub](https://github.com/esi/esi-issues/issues/1089)

---

<div class="post-metadata">

**Author:** ![Sissany\_Ravon](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/sissany_ravon/32/410278_2.png) [@Sissany\_Ravon](https://forums.eveonline.com/u/Sissany_Ravon)\
**Post date:** [October 15, 2021, 6:58pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/11 "2021-10-15T18:58:53Z")

</div>

Yep! That did it!

```
GET https://esi.evetech.net/latest/characters/726604936/skills/ HTTP/1.1
Host: esi.evetech.net
Authorization: Bearer <omitted>
	
HTTP/1.1 200 OK
Date: Fri, 15 Oct 2021 18:55:13 GMT
<header omitted>

{"skills":[{"active_skill <cutoff>

```

The worst part is that I remembered that I thought I should just try one, but then my lazy brain went “naa, just pick everything!”. Thank you SO MUCH for that!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/eveonline/original/3X/4/1/41ec4921cbaca7a6f9ea556e7cc20018461eae5e.png) [@system](https://forums.eveonline.com/u/system)\
**Post date:** [January 13, 2022, 6:59pm UTC](https://forums.eveonline.com/t/authentication-works-but-cant-use-token-in-esi-call/332409/12 "2022-01-13T18:59:21Z")

</div>

Closed on January 13, 2022, 6:59pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
