# How to get access token in angular with '@auth0/auth0-angular' library

**URL:** <https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459>\
**Category:** Get Help\
**Tags:** access-token\
**Created:** [September 12, 2022, 5:58pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459 "2022-09-12T17:58:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaydeeps03](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jaydeeps03/32/36419_2.png) [@Jaydeeps03](https://community.auth0.com/u/Jaydeeps03)\
**Post date:** [September 12, 2022, 5:58pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459/1 "2022-09-12T17:58:05Z")

</div>

Please include the following information in your post:

- Which SDK this is regarding: auth0/auth0-angular
- SDK Version: 1.10.1
- Platform Version: Angular 12
- Code Snippets/Error Messages/Supporting Details/Screenshots:

Hi Team,

I am using above mentioned sdk to configure Auth0 in my angular application.

I have imported AuthModule in my module.ts as below.

![image](https://global.discourse-cdn.com/auth0/original/3X/1/6/1610c06cec2e2f01c506f2bad1a41fa541d8f0c5.png)

In my auth-callback component, I am want to get access token, but when I call ‘handleRedirectCallback’ then I get below error:

![image](https://global.discourse-cdn.com/auth0/original/3X/9/5/952c8efb3b80d74fae9a9966ffed947cd5ac7a85.png)

 ![image](https://global.discourse-cdn.com/auth0/original/3X/c/f/cf9cdc8dc618a8cff33004a4d0abe59edb1b34cf.png)

As per the stackoverflow thread, we dont need to call ‘handleRedirectCallback()’

> <https://stackoverflow.com/questions/70218366/angular-auth0-invalid-state-issue>

but as per the library comment, we should call this function:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/3/e/3e7bb535bec5e801c44da99fec7d4e2e1e727642.png)

It’s really confusing, can someone help here?

Thanks,  
Jaydeep S

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 12, 2022, 10:43pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459/2 "2022-09-12T22:43:28Z")

</div>

Hey there @Jaydeeps03!

I believe the documentation may be out of date here in saying that you need to call `handleRedirectCallback()` directly:

> <https://github.com/auth0/auth0-angular/issues/249#issuecomment-986361377>
>
> \### Describe the problem
> I'm getting the error "Invalid state" when using the \`…AuthGuard\` on my routes. I have a setup where all my routes have that guard except for my callback route.
> 
> When trying to debug I set a breakpoint in \`redirectIfUnauthenticated\` and I am seeing some strange behavior where \`isAuthenticated\` is true, and then very shortly therafter it is false which causes the application to try and get a new token when it shouldn't. I believe that is causing the invalid state error. 
> 
> !\[image\](https://user-images.githubusercontent.com/16483662/144540784-b8a40093-282f-49fc-b914-f09459259308.png)
> 
> \### What was the expected behavior?
> I can see (on an app where it is working) that the "healthy" behavior is:
> 1. User is authenticated so \`isAuthenticated\` is true anytime its observed
> 2. User is not authenticated so \`isAuthenticated\` is false first and then \`true\` anytime its observed thereafter
> 
> \### Reproduction
> I tried to create an minimal reproducible example on a new application with the same version of angular and auth0/angular but haven't been able to reproduce which leads me to believe there is something in my code causing this issue. Is there anything you could recommend I look at to try and figure out why it thinks its unauthenticated when it actually is? 
> 
> Things I've tried:
> \- observed the cookies to see if they change between states (they don't)
> \- looked for any instances of logout
> 
> \### Environment
> \- \*\*Version of \`auth0-angular\` used:\*\* 
> \- \*\*Which browsers have you tested in?\*\* Chrome
> \- \*\*Which version of Angular have you tested with?\*\* 10.1.5
> \- \*\*Other modules/plugins/libraries that might be involved:\*\* 1.8.0

---

<div class="post-metadata">

**Author:** ![Jaydeeps03](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jaydeeps03/32/36419_2.png) [@Jaydeeps03](https://community.auth0.com/u/Jaydeeps03)\
**Post date:** [September 15, 2022, 2:13pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459/5 "2022-09-15T14:13:08Z")

</div>

hey I done some more research and come to know that we have to call handleRedirectCallback() function in call back URL. I was getting ‘Invalid State’ error because I made mistake while importing auth module, somehow I was initiating that twice in my application and this was causing generating two different states.

Hope this will help someone in future.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 20, 2022, 8:12pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459/6 "2022-09-20T20:12:08Z")

</div>

Awesome, good to know you were able to get this sorted and thanks for following up with the community 🙂

---

<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:** [October 4, 2022, 8:12pm UTC](https://community.auth0.com/t/how-to-get-access-token-in-angular-with-auth0-auth0-angular-library/90459/7 "2022-10-04T20:12:18Z")

</div>

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