title: Loopback 4 OpenAPI connector: Specify Authorization header value per request
body: <p>I have set up an OpenAPI connector in Loopback 4 as described <a href="https://loopback.io/doc/en/lb3/OpenAPI-connector.html#loopback-4-usage" rel="nofollow noreferrer">here</a> and for unauthorized requests, it is working well; I managed to create the respective datasource, service and controller. My service is similar to the <a href="https://github.com/strongloop/loopback-next/blob/master/examples/todo/src/services/geocoder.service.ts" rel="nofollow noreferrer">GeocoderProvider example</a>, but, let's say, with the following service interface.</p>
  
  <pre><code>export interface MyExternalService {
    search_stuff(params: {query?: string}): Promise&lt;MyExternalServiceResponse&gt;;
  }
  
  export interface MyExternalServiceResponse {
    text: string;
  }
  </code></pre>
  
  <p>From my controller, I invoke it like this, where <code>this.myExternalService</code> is the injected service (kind of unrelated, but can Loopback also implicitly parse a JSON response from an external API datasource?):</p>
  
  <pre><code>  @get('/search')
    async searchStuff(@param.query.string('query') query: string): Promise&lt;void&gt; {
      return JSON.parse(
        (await this.myExternalService.search_stuff({query})).text,
      );
    }
  </code></pre>
  
  <p>Now, the external endpoint corresponding to <code>myExternalService.search_stuff</code> needs an <code>Authorization: Bearer &lt;token&gt;</code> header, where the token is sent to Loopback <em>by the client</em>, i.e. it's not a static API key or so. Assuming I added <code>@param.query.string('token') token: string</code> to the parameter list of my <code>searchStuff</code> controller method, how can I forward that token to the OpenAPI connector? This is the relevant part of the underlying OpenAPI YAML definition file:</p>
  
  <pre><code>paths:
    /search:
      get:
        security:
          - Authorization: []
        responses:
          '200':
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/SearchResults'
        operationId: search-stuff
  components:
    securitySchemes:
      Authorization:
        type: http
        scheme: Bearer
  </code></pre>