# API call with permissions/scopes Angular

**URL:** <https://community.auth0.com/t/api-call-with-permissions-scopes-angular/52165>\
**Category:** Get Help\
**Tags:** api, permissions, angular, login, auth0\
**Created:** [October 26, 2020, 4:54am UTC](https://community.auth0.com/t/api-call-with-permissions-scopes-angular/52165 "2020-10-26T04:54:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardo.ozanan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eduardo.ozanan/32/14412_2.png) [@eduardo.ozanan](https://community.auth0.com/u/eduardo.ozanan)\
**Post date:** [October 26, 2020, 4:54am UTC](https://community.auth0.com/t/api-call-with-permissions-scopes-angular/52165/1 "2020-10-26T04:54:52Z")

</div>

Hi guys,

I’m trying to implement an API with protected endpoints (permissions/scopes) and call this API from my angular application and I’d like to know the correct way to pass these extra scopes to my API in my access\_token.

I created an API and set the permissions in Auth0 following these steps: [https://auth0.com/docs/quickstart/backend/aspnet-core-webapi/01-authorization](https://auth0.com/docs/quickstart/backend/aspnet-core-webapi/01-authorization)

My .NET Core Web API is working fine. My endpoints have the [Authorize(“my\_scope”)] annotation, so the access\_token from my angular app must have these scopes in it.

I set up my angular App following these steps: [Add Login to Your Angular Application - Auth0 Docs](https://auth0.com/docs/quickstart/spa/angular/01-login)

I’m using the Authorization Core and have enabled the RBAC and Add Permissions in the Access token options and I’m allowing Skipping User Consent.

For my Angular app, I’m using the @auth0/auth0-angular library following the quickstart sample using the loginWithRedirect() method and Universal Login (Classic)

I couldn’t find any proper example of how to pass the scopes/permissions to the API using @auth0/auth0-angular with loginWithRedirect().

The wat I implemented it was:

loginWithRedirect() {  
this.auth.loginWithRedirect(({  
scope: ‘openid profile email read:sponsors create:sponsor read:programs delete:sponsor-program-enrolment’  
}));  
}

and

httpInterceptor: {  
allowedList: [  
{  
uri: `${apiUrl}/*`,  
tokenOptions: {  
// The attached token should target this audience  
audience: ‘my\_audience’,  
// The attached token should have these scopes  
scope: ‘openid profile email read:sponsors create:sponsor read:programs delete:sponsor-program-enrolment’  
}  
}  
]  
}

Is this implementation correct to get the user’s permission/scopes and attach them to my token? Just want to make sure if that’s is the correct approach to do it.

The implementation above worked for me except I need to refresh the browser manually (F5) after the login to see the protected menu on my home page.

On my home page screen, I check if the user IsAuthtcated and if so, the login button is not displayed and I display some options on the Navbar.  
\<ng-container \*ngIf=“auth.isAuthenticated$ | async”\>

I noticed that this issue only happens after I put the scopes in the loginWithRedirect.

loginWithRedirect() {  
this.auth.loginWithRedirect(({  
scope: ‘openid profile email read:sponsors create:sponsor read:programs delete:sponsor-program-enrolment’  
}));  
}

If I simply call loginWithRedirect() without passing the scopes the home page displays the protected resources correctly without needing to refresh the browser. The problem is that I need to get these scopes when the user logs in to pass it to my API.

Have someone faced this issue before or have any suggestions on what is the correct way to implement it?

Cheers,  
Eduardo

---

<div class="post-metadata">

**Author:** ![eduardo.ozanan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eduardo.ozanan/32/14412_2.png) [@eduardo.ozanan](https://community.auth0.com/u/eduardo.ozanan)\
**Post date:** [October 30, 2020, 12:29am UTC](https://community.auth0.com/t/api-call-with-permissions-scopes-angular/52165/2 "2020-10-30T00:29:25Z")

</div>

Solution for the isAuthenticated$ delay:

> [@isAuthenticated fails on login, works on refresh](https://community.auth0.com/t/isauthenticated-fails-on-login-works-on-refresh/42515/26):
>
> Hey, @dan-auth0 thanks for your reply. I’m pretty much doing exactly like [Auth0 Angular SDK Quickstarts: Login](https://auth0.com/docs/quickstart/spa/angular/01-login) the angular quickstart, that’s pretty much the architecture my app is following, the only difference is I was passing the custom scopes in the loginWithRedirect() method and it was causing a delay I don’t know why. And also I included these scopes in httpInterceptor tokenOptions. But I think I found a solution yesterday: I don’t know why but if I set my scopes in the authentication mo…
