# Invalid access token - ionic 2+ SDK quickstart

**URL:** <https://community.auth0.com/t/invalid-access-token-ionic-2-sdk-quickstart/7902>\
**Category:** Get Help\
**Tags:** quickstart, mobile, api-authorization, ionic2, access-token\
**Created:** [August 19, 2017, 7:22am UTC](https://community.auth0.com/t/invalid-access-token-ionic-2-sdk-quickstart/7902 "2017-08-19T07:22:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![findbl0k](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@findbl0k](https://community.auth0.com/u/findbl0k)\
**Post date:** [August 19, 2017, 7:22am UTC](https://community.auth0.com/t/invalid-access-token-ionic-2-sdk-quickstart/7902/1 "2017-08-19T07:22:38Z")

</div>

I’ve spent a few days down this rabbit hole and I’m hoping someone here can help. I’m creating a mobile app based on the [Auth0 Ionic 2+ SDK Quickstart](https://auth0.com/docs/quickstart/native/ionic2/01-login). The login and redirect works great, and I retrieve a valid idToken. However, the access token I need to authenticate with my API does not appear to be valid. I already have an angular 4 front-end that successfully authenticates with my express backend; the problem here is that I’m not getting valid access tokens in my ionic app.

```
example access token: IdCKy7eYbl0pwxtE

```

Above is an example accessToken that I get back in the ionic app, and when I send this to my API as an authorization header I get: UnauthorizedError: jwt malformed. This looks to me like a refresh token, but when I send a post request to: [https://findbl0k.auth0.com/oauth/token](https://findbl0k.auth0.com/oauth/token) with the following payload it says my refresh token is invalid.

```
request:
{ 
    "grant_type": "refresh_token",
    "client_id": "yecF47olgqyu0GadqfIRBDcB8JWufsg-",
    "refresh_token": "IdCKy7eYbl0pwxtE"
}
response: 
{
    "error": "invalid_grant",
    "error_description": "Unknown or invalid refresh token."
}

```

here’s my config in auth.services.ts:

```
const auth0Config = {

  // needed for auth0
  clientID: 'yecF47olgqyu0GadqfIRBDcB8JWufsg-',
  audience: 'https://findbl0k.auth0.com/api/example',

  // needed for auth0cordova
  clientId: 'yecF47olgqyu0GadqfIRBDcB8JWufsg-',
  domain: 'findbl0k.auth0.com',
  callbackURL: location.href,
  packageIdentifier: 'io.ionic.starter.auth0',
  scope: 'openid profile read:messages'
};

```

I’m not sure why this access token is invalid. Any help here is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![findbl0k](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@findbl0k](https://community.auth0.com/u/findbl0k)\
**Post date:** [August 21, 2017, 4:14am UTC](https://community.auth0.com/t/invalid-access-token-ionic-2-sdk-quickstart/7902/2 "2017-08-21T04:14:37Z")

</div>

Hi guys,

I figured this out. I’ll post the answer here for anyone googling how to access a secured auth0 API from Ionic 2+. I set the audience parameter in the auth0config object, but I needed to set the audience for auth0cordova. On line 57 of the src/services/auth.service.ts you have to edit the `options` object in the public login function to include the correct audience and scope.

```
public login() {
    const client = new Auth0Cordova(auth0Config);

    const options = {
      scope: 'openid profile offline_access'
    };

    ...

```

add the audience parameter like this:

```
const options = {
      scope: 'openid profile read:messages',
      audience: 'https://findbl0k.auth0.com/api/example',
    };

```

Hopefully this helps someone who was struggling like me.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:56am UTC](https://community.auth0.com/t/invalid-access-token-ionic-2-sdk-quickstart/7902/3 "2018-03-02T05:56:01Z")

</div>


