r0man / oauth-clj

Clojure OAuth library
95 stars 27 forks source link

How do you make a client that doesn't require a web redirect? #31

Open jaidetree opened 5 years ago

jaidetree commented 5 years ago

I'm working with an API that uses oauth v1 but doesn't require a web callback and redirect to get the access token. Is that called an out of band request? How do I use the v1 api in this library to do that?

jaidetree commented 5 years ago

I ended up figuring it out by reverse engineering the API provider's working Ruby example!

It turns out in this case you don't need to get a request token or access token directly. Instead we just want to generate the signature, nonce, and the rest of the authorization headers for each request to the API.

(ns my-api-wrapper.core
  (:require [oauth.v1 :refer [make-consumer]]
            [config.core :refer [env]]))

(def public-token (:public-token env))
(def secret-key (:secret-key env))

(def client (make-consumer
             :oauth-consumer-key public-token
             :oauth-consumer-secret secret-key))

(client {:method :get
         :url "https://api.domain.com/v1/data.json"})

Or perhaps this API provider is functioning in a non-standard way?