title: NestJS: Adding verification options to AuthGuard with JWT
body: <p>I am trying to make use of the <code>AuthGuard</code> decorator, and the passport JWT strategy, following the <a href="https://docs.nestjs.com/techniques/authentication" rel="noreferrer">documentation</a>.</p>
  
  <p>Everything in the documentation works great. But I now want to protect a route with a scope contained in the JWT. So here is a basic jwt payload generated by my application:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "user": {
      "id": "20189c4f-1183-4216-8b48-333ddb825de8",
      "username": "user.test@gmail.com"
    },
    "scope": [
      "manage_server"
    ],
    "iat": 1534766258,
    "exp": 1534771258,
    "iss": "15f2463d-8810-44f9-a908-801872ded159",
    "sub": "20189c4f-1183-4216-8b48-333ddb825de8",
    "jti": "078047bc-fc1f-4c35-8abe-72834f7bcc44"
  }
  </code></pre>
  
  <p>Here is the basic protected route being guarded by the <code>AuthGuard</code> decorator:</p>
  
  <pre class="lang-js prettyprint-override"><code>@Get('protected')
  @UseGuards(AuthGuard('jwt'))
  async protected(): Promise&lt;string&gt; {
      return 'Hello Protected World';
  }
  </code></pre>
  
  <p>I would like to add options and restrict the access of that route to the people having the <code>manager_server</code> scope into their JWT. So after reading a little bit of the <code>AuthGuard</code> code, I thought that I was able to write something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>@Get('protected')
  @UseGuards(AuthGuard('jwt', {
      scope: 'manage_server'
  }))
  async protected(): Promise&lt;string&gt; {
      return 'Hello Protected World';
  }
  </code></pre>
  
  <p><strong>However, I can't see in the documentation where I could make use of this option.</strong> </p>
  
  <p>I thought that adding an option argument to the <code>validate</code> function of the <code>JWTStrategy</code> could make the trick, but it does not. Here is my <code>validate</code> function (contained in the <code>jwt.strategy.ts</code> file):</p>
  
  <pre class="lang-js prettyprint-override"><code>async validate(payload: JwtPayload, done: ((err: any, value: any) =&gt; void)) {
      const user = await this.authService.validateUser(payload);
      if (!user) {
          return done(new UnauthorizedException(), false);
      }
      done(null, user);
  }
  </code></pre>
  
  <p>Thank you very much for your help and don't hesitate to ask me for more informations in the comments if you need so.</p>