Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling in express routes #30

Closed
dibishks opened this issue Oct 24, 2019 · 1 comment
Closed

Error handling in express routes #30

dibishks opened this issue Oct 24, 2019 · 1 comment

Comments

@dibishks
Copy link

I am using 'express-jwt-authz' to validate the scope of a jwt token, I implemented the flow like below. Here when I am calling 'checkScopes' function from my routes but it will never return the result, the callback of 'jwtAuthz' is not throwing any success or error condition. How to check error handling in 'express-jwt-authz' auth npm.

Middleware 

    validation.js 

    const jwt = require('express-jwt');
    const jwtAuthz = require('express-jwt-authz');
    const jwksRsa = require('jwks-rsa');
    const config = require('../config/config');
    module.exports.checkScopes = function(options) {
      return function(req, res, next) {
        jwtAuthz(options, {customScopeKey: 'http://user.com/scopes'}, function(error) {
          if (error) {
            console.log('error', error)
          } else {
            console.log('result never called')
            next();
          }
        })
      }
    }

Routes 
    invitation.js 

    const express = require('express');
    const router = express.Router();
    const jwtValidation = require('../middleware/jwtValidation');
    router.get('/', jwtValidation.checkScopes([ 'create:users' ]), invitation.getAllInvitation);
@dibishks dibishks changed the title Callba Error handling in express routes Oct 25, 2019
@joshcanhelp
Copy link

@dibishks - Have you tried using as a middleware directly, as explained in the README?

https://github.com/auth0/express-jwt-authz#usage

I'm also seeing that you're pulling in express-jwt but not using it. You'll want to verify the token first before checking the scopes.

@joshcanhelp joshcanhelp self-assigned this Oct 25, 2019
@joshcanhelp joshcanhelp removed their assignment Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants