0

I'm using Angular and Node.js with Auth0 for the login. I using the quick start guide to get the API started. Here is my backend that uses the Auth0 API.

var jwtCheck = jwt({
    secret: jwks.expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: 'https://xxxx.auth0.com/.well-known/jwks.json'
  }),
  audience: 'http://localhost:3002',
  issuer: 'https://xxxx.auth0.com/',
  algorithms: ['RS256']
});

app.get('/authorized', function (req, res) {
    res.send('Secured Resource');
});

After I've logged in using the Auth0 universal login, I then try to access my backend and see if I'm authorized.

Here is the code that checks to see if I'm authorized.

  tempCheck() {
    this.http.get("http://localhost:3002/authorized").subscribe(data => {
      console.log(data);
    });
  }

Note, I'm not passing anything ( I would think I need to but the Auth0 guide isn't telling me so).

After checking to see if I'm authorized I get the error No autho token was found. Not sure what I'm doing here. Is my backend not correctly hooked up?

The idea here is to login with Auth0. Then anytime I want to preform a CRUD action with my database, I'd like to use my backend first to validate the user before performing CRUD actions.

Any help would be greatly appreciated.


Update: I went through testing and it makes more sense to me. So when I start up my server to use Auth0. I have to get the token and use it with Auth0. In some way I'm validating with Auth0 to make my server able to use the Auth0.

Now my server is validated.

Then when a user wants to perform a CRUD action, I send his/her unique Auth0 ID, validate it on my server and then perform the action if he/she is valid.

JD333
  • 501
  • 8
  • 22

1 Answers1

0

If you have token, then with each service you have to provide it in header with the key Authorization. At server this token will be validated. Read more How to add Authorization Header to Angular http request?. In this Angular framework used but for normal JavaScript you have to provide it in your ajax call.

mukund patel
  • 1,039
  • 10
  • 31
  • Hey I just added and update. What do you think about it? – JD333 Nov 09 '19 at 19:34
  • The Auth0 ID changes everytime the user logs in yes? Or no it doesn't. So if someone got that ID, they could simply use it to update things? – JD333 Nov 09 '19 at 19:39
  • Yes. It is generated by your provided user details, time and some other dynamic keys. To make it unique. – mukund patel Nov 09 '19 at 19:41