IBM / openapi-to-graphql

Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
https://developer.ibm.com/open/projects/openapi-to-graphql/
MIT License
1.61k stars 211 forks source link

Multi tenant oauth1 #137

Open lingwooc opened 5 years ago

lingwooc commented 5 years ago

I'm using your library to wrap the xero api. So far so good. I can get 1 legged oauth1 working like so:

const oas = require('./openAPI/Xero_accounting_2.0.0_swagger.json');
        let oauth =
            {oauth:{ consumer_key: user.consumerKey,
                    token: user.consumerKey,
                    private_key: user.consumerSecret,
                    signature_method : 'RSA-SHA1'
                }};
        let {schema} = await OASGraph.createGraphQlSchema(oas,{requestOptions: oauth});

This is fine, you get support for free from request.

But if I want to change the oauth settings I have to recreate the whole schema. I can't use tokenJSONpath as oauth1 doesn't work that way. Perhaps the best way would be to allow request to be wrapped by some form of middleware so any form of auth (or auto retry for rate limiters etc) could be supported.

(yes oauth1 is old, tell it to xero)

lingwooc commented 5 years ago

I've set my fork of oasgraph to load the request options from the request context. I've also set it to save the response headers to the context. It seems like a minimal method for solving this issue and helping with request diagnostics/rate limits.

I'll do a PR in due course.

Alan-Cha commented 5 years ago

Ah great! So sorry for the lack of response! This slipped under my radar. It seems like you found a workaround but let us know if you have any trouble. We would highly appreciate a PR so if you are willing, please go for it! 😄