# Angular 16 SSO Refresh Token Issues

**URL:** <https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290>\
**Category:** Third Party Developers\
**Created:** [November 11, 2023, 7:02pm UTC](https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290 "2023-11-11T19:02:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryvrals](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/ryvrals/32/393891_2.png) [@Ryvrals](https://forums.eveonline.com/u/Ryvrals)\
**Post date:** [November 11, 2023, 7:02pm UTC](https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290/1 "2023-11-11T19:02:42Z")

</div>

Hello, all. I’m working on a new Angular app and having trouble using the refresh token. I hope that some of you that have had success with angular will give me a few tips as to what I’m doing wrong.

My function is to request a new auth token using the refresh token. Referencing these docs: [Refreshing tokens](https://docs.esi.evetech.net/docs/sso/refreshing_access_tokens.html)

```auto
    const client_id = environment.eveClientId;
    const secret_key = environment.eveSecretKey;
    const auth = btoa(`${client_id}:${secret_key}`);

    var refresh_token = this.storageService.getEveRefreshToken();

    const headers = new HttpHeaders();
    headers.append('Authorization', `Basic ${auth}`);
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    headers.append('Host', 'login.eveonline.com');
    const httpOptions = { headers: headers};

    // EVE notes:
    // Remember that the refresh token must be URL-encoded, per the content type of the request.
    // Failing to do this may cause the request to be malformed and a 400 response to be returned.
    const encodedBody = new URLSearchParams();
    encodedBody.set('grant_type', 'refresh_token');
    encodedBody.set('refresh_token', `${refresh_token}`);

    return this.http.post<EveTokenModel>('https://login.eveonline.com/v2/oauth/token', encodedBody, httpOptions);

```

I always receive a 401 error:

```auto
{
    "headers": {
        "normalizedNames": {},
        "lazyUpdate": null,
        "headers": {}
    },
    "status": 401,
    "statusText": "OK",
    "url": "https://login.eveonline.com/v2/oauth/token",
    "ok": false,
    "name": "HttpErrorResponse",
    "message": "Http failure response for https://login.eveonline.com/v2/oauth/token: 401 OK",
    "error": null
}
```

I have tried to encodeURIComponent the refresh\_token but received the same 401 error.

I have no trouble receiving the token via the original SSO request and can access ESI endpoints. The only problem that I’m facing is the refresh token. I store the token and the refresh token in local storage (for testing) . I ensure to update these as new SSO requests are made.

Any tips would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Joao\_Neto](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/joao_neto/32/382825_2.png) [@Joao\_Neto](https://forums.eveonline.com/u/Joao_Neto)\
**Post date:** [November 13, 2023, 11:10am UTC](https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290/2 "2023-11-13T11:10:04Z")

</div>

It’s very similar to my implementation, which works without issues.

The only weird thing I found is this line:

```auto
    var refresh_token_url_encoded = encodeURIComponent(refresh_token!);

```

Not sure why you’re encoding it here, as I believe it is also encoded once you add it to the URLSearchParams.

---

<div class="post-metadata">

**Author:** ![Ryvrals](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/ryvrals/32/393891_2.png) [@Ryvrals](https://forums.eveonline.com/u/Ryvrals)\
**Post date:** [November 13, 2023, 7:51pm UTC](https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290/3 "2023-11-13T19:51:52Z")

</div>

That was just for testing.

---

<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:** [February 11, 2024, 7:51pm UTC](https://forums.eveonline.com/t/angular-16-sso-refresh-token-issues/427290/4 "2024-02-11T19:51:58Z")

</div>

Closed on February 11, 2024, 7:51pm UTC

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