title: Nestjs azure active directory and graphql - UseGuard
body: <p>Building an API with nestjs and graphql I want to implement Azure Active Directory for authorization.
  They provide a  <code>passport-azure-ad</code> package with a strategy.
  It is working just fine when I add a nestjs guard to a REST endpoint, but with a GrapQL resolver it is throwing an error <code>Cannot read property 'query' of undefined</code>.</p>
  <p>Nestjs <a href="https://docs.nestjs.com/techniques/authentication#graphql" rel="nofollow noreferrer">docs</a> give some hint, but I have no idea how to implement and make the graphql query available to the passport strategy.</p>
  <p>My guard looks as follows:</p>
  <pre><code>import { Injectable } from '@nestjs/common';
  import { PassportStrategy, AuthGuard } from '@nestjs/passport';
  import { BearerStrategy } from 'passport-azure-ad';
  import * as dotenv from 'dotenv';
  dotenv.config();
  
  const clientID = process.env.AZURE_AD_CLIENT_ID;
  const tenantID = process.env.AZURE_AD_TENANT_ID;
  
  /**
   * Extracts ID token from header and validates it.
   */
  @Injectable()
  export class AzureADStrategy extends PassportStrategy(
    BearerStrategy,
    'azure-ad',
  ) {
    constructor() {
      super({
        identityMetadata: `https://login.microsoftonline.com/${tenantID}/v2.0/.well-known/openid-configuration`,
        clientID,
      });
    }
    
    async validate(data) {
      console.log(data);
      return data;
    }
  }
  
  export const AzureADGuard = AuthGuard('azure-ad');
  </code></pre>
  <p>GraphQL config from <code>app.module.ts</code></p>
  <pre><code>...
  imports: [
   GraphQLModule.forRoot({
        autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
        sortSchema: true,
        context: ({ req }) =&gt; ({ req }),
      }),
  ...
  </code></pre>