This repository has been archived by the owner on Nov 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.clj
44 lines (39 loc) · 1.58 KB
/
auth.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns copy-api.auth
(:require [oauth.client :as oauth]))
(defn make-consumer
"Takes an API key and secret and returns a Copy OAuth consumer. The
next step is to call request-token with the consumer returned
here(optionally with a callback-url)."
[consumer-key consumer-secret]
(oauth/make-consumer consumer-key
consumer-secret
"https://api.copy.com/oauth/request"
"https://api.copy.com/oauth/access"
"https://www.copy.com/applications/authorize"
:hmac-sha1))
(defn request-token
"Takes a consumer and optionally a callback-uri and returns a request
token that user will need to authorize."
[consumer callback-uri]
(oauth/request-token consumer callback-uri))
(defn authorization-url
"Takes a consumer and request-token and returns a URL to send the
user to in order to authenticate."
[consumer request-token]
(oauth/user-approval-uri consumer
(:oauth_token request-token)))
(defn access-token-response
"Takes a consumer and request-token and returns a map with
:oauth_token and :oauth_token_secret."
[consumer request-token verifier]
(oauth/access-token consumer
request-token
verifier))
(defn make-credentials
[consumer access-token-response method url body]
(oauth/credentials consumer
(:oauth_token access-token-response)
(:oauth_token_secret access-token-response)
method
url
body))