thinhle-agilityio / gatsby-source-apiserver

A gatsby source plugin for pulling data from api server.
63 stars 34 forks source link

Oauth2 Permission Denied #33

Open jasecoop opened 5 years ago

jasecoop commented 5 years ago

Hi

I was hoping someone might be able to point me in the right direction in implementing the auth0config for OAuth2. I'm getting "401 not authorised" every time. Here's my code (client_secret redacted):

module.exports = {
  plugins: [
    {
      resolve: "gatsby-source-apiserver",
      options: {
        typePrefix: 'internal__',
        url: `https://api.ochre.io/v1/stores/`,
        method: 'get',
        headers: {
          "Content-Type": "application/json"
        },
        name: `posts`,
        auth0Config: {
          method: "GET",
          url: "https://auth.ochre.io/oauth2/token",
          headers: {
            "content-type": "application/json"
          },
          data: {
            grant_type: "client_credentials",
            scope: "CMS RETAIL MUSIC",
            client_id: "9939492",
            client_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
          },
          json: true
        },
        params: {
          results: 100
        },
        verboseOutput: true,
    }
    },
  ],
}

Has anyone used gatsby-source-apiserve for Oauth2, is it possible?

jasecoop commented 5 years ago

auth0Config was returning undefined.

I've forked the code and I have it working using 'axios-oauth-client'

Happy to share the code if useful. Curious what you might thing.

thinhle-agilityio commented 5 years ago

thanks for your contribution @jasecoop , can you submit a PR then I can have a review?