groovy-wslite icon indicating copy to clipboard operation
groovy-wslite copied to clipboard

OAuth Support

Open restagner opened this issue 9 years ago • 3 comments

Does groovy-wslite support OAuth?

restagner avatar Jun 09 '15 15:06 restagner

No support built in.

jwagenleitner avatar Jun 09 '15 17:06 jwagenleitner

Ok. You mention that no support is built in, which leads to ask if something like SignPost (https://github.com/mttkay/signpost) could work with groovy-wslite. Or, possibly some other OAuth framework .. in your mind, is that even feasible?

restagner avatar Jun 09 '15 21:06 restagner

It looks like it would be feasible to use signpost since it works with an HttpURLConnection. A custom HTTPAuthorization can be passed to the client and it'll be called with the connection before the request is sent.

I have not tested this but something along the following lines might work:

OAuthConsumer consumer = .... // set up the signpost consumer

def client = new RESTClient("http://api.example.com/protected")

client.authorization = { HttpURLConnection connection -> 
    consumer.sign(connection)
} // as wslite.http.auth.HTTPAuthorization

def response = client.get .....

jwagenleitner avatar Jun 10 '15 03:06 jwagenleitner