# Auth0 Angular with proxy config settings

**URL:** <https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086>\
**Category:** Get Help\
**Tags:** scopes, auth0\
**Created:** [May 2, 2021, 12:56pm UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086 "2021-05-02T12:56:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hantsy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hantsy/32/29176_2.png) [@hantsy](https://community.auth0.com/u/hantsy)\
**Post date:** [May 2, 2021, 12:56pm UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086/1 "2021-05-02T12:56:13Z")

</div>

Auth0 Angular 1.4.1  
NodeJS 16  
Angular 11

The code codes can be found from my Github account, the codes are based on this auth0 blog.

> **[The Complete Guide to Angular User Authentication with Auth0](https://auth0.com/blog/complete-guide-to-angular-user-authentication/#Calling-an-API)**
>
> Learn how to add user authentication to Angular using Observables and HTTP Interceptors. Learn the core concepts of Angular authenticatio...

Check my example from the following repo:

> **[GitHub - hantsy/spring-security-auth0-sample: Spring Security 5 with...](https://github.com/hantsy/spring-security-auth0-sample)**
>
> Spring Security 5 with OAuth2/OIDC and Auth0 integration example - GitHub - hantsy/spring-security-auth0-sample: Spring Security 5 with OAuth2/OIDC and Auth0 integration example

I am trying to use a proxy config to bypass the cors issue, it worked well in the past years.

The proxy config file is [here](https://github.com/hantsy/spring-security-auth0-sample/blob/master/ui/proxy.conf.json).

When I tried to create a post, the browser raised a 401 error.

```bash
Status401
Unauthorized
VersionHTTP/1.1
Transferred1.40 KB (0 B size)
Referrer Policystrict-origin-when-cross-origin

```

In the backend API, the console printed the following logs.

```bash
2021-05-02 20:45:02.097 DEBUG 18068 --- [io-8080-exec-10] o.s.security.web.FilterChainProxy : Securing POST /posts
2021-05-02 20:45:02.097 DEBUG 18068 --- [io-8080-exec-10] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2021-05-02 20:45:02.099 DEBUG 18068 --- [io-8080-exec-10] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2021-05-02 20:45:02.099 DEBUG 18068 --- [io-8080-exec-10] o.s.s.w.session.SessionManagementFilter : Request requested invalid session id b908a19252e9509245bebb463418
2021-05-02 20:45:02.100 DEBUG 18068 --- [io-8080-exec-10] o.s.s.w.a.i.FilterSecurityInterceptor : Failed to authorize filter invocation [POST /posts] with attributes [hasAuthority('SCOPE_write:posts')]
2021-05-02 20:45:02.100 DEBUG 18068 --- [io-8080-exec-10] s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request

```

Note: the backend API is tested by JUnit and Spring Boot test utilities.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 4, 2021, 2:32pm UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086/3 "2021-05-04T14:32:48Z")

</div>

Hi @hantsy,

Welcome to the Community!

From the error, it looks like the scope of the bearer Access Token does not contain the expected scope:

```auto
hasAuthority('SCOPE_write:posts')

```

If you decode the Access Token that your app is sending in the request, does it look like the correct scope is set? [https://jwt.io/](https://jwt.io/)

It looks like the Angular app is using `write:posts` ([spring-security-auth0-sample/app.module.ts at f9351c6b04c3ff9b6fa062e93c8d45f1662727f2 · hantsy/spring-security-auth0-sample · GitHub](https://github.com/hantsy/spring-security-auth0-sample/blob/f9351c6b04c3ff9b6fa062e93c8d45f1662727f2/ui/src/app/app.module.ts#L25)), but the API is expecting `SCOPE_write:posts` ([spring-security-auth0-sample/SecurityConfig.java at f9351c6b04c3ff9b6fa062e93c8d45f1662727f2 · hantsy/spring-security-auth0-sample · GitHub](https://github.com/hantsy/spring-security-auth0-sample/blob/f9351c6b04c3ff9b6fa062e93c8d45f1662727f2/api/src/main/java/com/example/demo/config/SecurityConfig.java#L40)), but there could be some parsing going on in the API that I’m not seeing.

---

<div class="post-metadata">

**Author:** ![hantsy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hantsy/32/29176_2.png) [@hantsy](https://community.auth0.com/u/hantsy)\
**Post date:** [May 5, 2021, 5:55am UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086/4 "2021-05-05T05:55:11Z")

</div>

@stephanie.chamblee Thanks, added `allowedList` and `scope` to the angular application to fix this problem.

Now my example is working well.

(personally, I think the `allowedList` is a bad naming there, in my first impression, it is the list of bypass token checking)

I think the spring security will convert scopes to its authority with a `SCOPE_` prefix.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 5, 2021, 11:13am UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086/5 "2021-05-05T11:13:53Z")

</div>

That’s great! Glad your example is working now 🙂

---

<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:** [May 20, 2021, 11:14am UTC](https://community.auth0.com/t/auth0-angular-with-proxy-config-settings/62086/6 "2021-05-20T11:14:17Z")

</div>

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