# Connect angular and express apps

**URL:** <https://community.auth0.com/t/connect-angular-and-express-apps/87135>\
**Category:** Get Help\
**Created:** [July 18, 2022, 3:37pm UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135 "2022-07-18T15:37:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavebor144](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pavebor144/32/33718_2.png) [@pavebor144](https://community.auth0.com/u/pavebor144)\
**Post date:** [July 18, 2022, 3:37pm UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135/1 "2022-07-18T15:37:42Z")

</div>

Hello,

I’m trying to secure an Angular application I made as well as the respective backend API written in express.

I have implemented angular and express apps according to configuration provided in guides. But when I try to hit my API I always get No authorization token was found error.

Any thoughts what I’m doing wrong?

Angular config

```auto
...
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AuthHttpInterceptor, AuthModule } from '@auth0/auth0-angular';

@NgModule({
  declarations: [
   ...
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    RouterModule.forRoot(routesConfig),
    ReactiveFormsModule,
    AuthModule.forRoot({
      // The domain and clientId were configured in the previous chapter
      domain: 'XXX.eu.auth0.com',
      clientId: 'CLIENT_ID',
      redirectUri: 'https://localhost:4200/entites',
    
      // Request this audience at user authentication time
      audience: 'https://XXX.eu.auth0.com/api/v2/',
    
      // Request this scope at user authentication time
      // scope: 'read:current_user',
    
      // Specify configuration for the interceptor              
      httpInterceptor: {
        allowedList: [
          {
            uri: 'https://XXX.eu.auth0.com/api/v2/*',
            tokenOptions: {
              // The attached token should target this audience
              audience: 'https://XXX.eu.auth0.com/api/v2/',
    
              // The attached token should have these scopes
              // scope: 'read:current_user'
            }
          }
          }
        ]
      }
    })
  ],
  providers: [
    ...
    { provide: HTTP_INTERCEPTORS, useClass: AuthHttpInterceptor, multi: true }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {

}

```

Angular API call

```auto
@Injectable()
export class MyService {

    constructor(private http: HttpClient) {
    }

    getAll() {
        return this.http.get('/api/entities');
    }
}

```

express config

```auto
...
import { expressJwtSecret } from 'jwks-rsa';
import { expressjwt } from 'express-jwt';

const checkJwt = expressjwt({
    secret: expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: 'https://XXX.eu.auth0.com/.well-known/jwks.json'
  }) as any,
  audience: 'https://localhost:4200/api',
  issuer: 'https://XXX.eu.auth0.com/',
  algorithms: ['RS256']
});

const bodyParser = require('body-parser');

const app: Application = express();

app.use(bodyParser.json());
app.use(cookieParser());
app.use(checkJwt);

// REST API
app.route('/api/entites').get(readAll);

httpsServer.listen(9000, () => console.log("HTTPS Server running at https://localhost:" + (httpsServer.address() as AddressInfo).port));

```

---

<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:** [July 19, 2022, 12:05am UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135/4 "2022-07-19T00:05:09Z")

</div>

Hello @pavebor144 welcome to the community!

> [@pavebor144](#):
>
> But when I try to hit my API I always get No authorization token was found error.

I assuming you are receiving a 401 here? This _typically_ means that there is no Access Token added to the authorization header in the request to the API like was the case in [this community topic](https://community.auth0.com/t/api-error-no-authorization-token-was-found/80391/2).

The following documentation regarding the `AuthHttpInterceptor` could be helpful:

> **[Auth0 Angular SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/angular/02-calling-an-api#provide-the-http-interceptor)**
>
> This tutorial demonstrates how to make API calls to the Auth0 Management API.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![pavebor144](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pavebor144/32/33718_2.png) [@pavebor144](https://community.auth0.com/u/pavebor144)\
**Post date:** [July 19, 2022, 6:17am UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135/5 "2022-07-19T06:17:22Z")

</div>

I found the problem. First of all I made some mistakes related to configuration. Additionally interceptor just failed to match my API when I provide a path which includes localhost.

```auto
...
      httpInterceptor: {
        allowedList: [
          'https://localhost:4200/api/*', // <= not working
          'localhost:4200/api/*', // <= not working
          '/api/*' // <= working
        ]
      }

```

Can you explain why full path doesn’t work?

---

<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:** [July 27, 2022, 12:33am UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135/6 "2022-07-27T00:33:15Z")

</div>

Sorry for the delayed response on this one, but glad to know you got the issue sorted!

> [@pavebor144](#):
>
> Can you explain why full path doesn’t work?

I’m not positive why the full uri isn’t respected, but the docs do show the use of the path:

> **[@auth0/auth0-angular](https://auth0.github.io/auth0-angular/#configure-authhttpinterceptor-to-attach-access-tokens)**
>
> Documentation for @auth0/auth0-angular

---

<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:** [August 11, 2022, 12:33am UTC](https://community.auth0.com/t/connect-angular-and-express-apps/87135/7 "2022-08-11T00:33:42Z")

</div>

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