SohoHouse / nuxt-oauth

Simple OAuth2 integration for your Nuxt app
MIT License
122 stars 27 forks source link

Allow OAuth2 to be instantiated with custom request #29

Closed vroad closed 5 years ago

vroad commented 5 years ago

This PR fixes #28. It adds an option to pass custom request handler in nuxt.config.js, which could be something like this:

require("dotenv").config();
const popsicle = require("popsicle");

// ...

module.exports = {
  // ...
  oauth: {
    // ...
    request: (method, url, body, headers) => {
      return popsicle
        .get({
          url: url,
          body: body,
          method: method,
          headers: headers,
          transport: popsicle.createTransport({
            // reject self-signed certificates only on production environment
            rejectUnauthorized:
              process.env.ALLOW_INSECURE_OAUTH_ENDPOINT === "0"
          })
        })
        .then(function(res) {
          return {
            status: res.status,
            body: res.body
          };
        });
    }
  },
};