qarth.oauth.lib documentation
Helper fns for OAuth implementations.
activate-record
(activate-record record param-map)
Helper fn for OAuth records. Dissocs :url and :state,
and adds the given keys and values.
csrf-token
(csrf-token)
Returns a random base-64 encoded 12-byte CSRF token.
do-activate
(do-activate service record code url parser)
Helper fn for OAuth v2 services. Uses clj-http to execute a token request
(described in make-token-request) and parses the response using the given parser fn.
The parser should return a map containing at least the key :access-token
and the optional key :expires-in. All keys will be added to the record.
service -- the auth service
record -- the auth record
code -- the auth code
url -- the access token url
parser -- a fn response-stream -> map, should return at least an :access-token
(be careful not to return access_token instead!)
The response stream will be closed if it isn't closed already when done.
do-new-record
(do-new-record {type :type, client_id :api-key, request-url :request-url, callback :callback, scope :scope, :as service} url extra-params)
Helper fn for new record suitable for standard OAuth v2.
Returns a new record with these fields:
:type -- same as the given service
:state -- a random state token
:url -- a GET-formatted url with standard OAuth v2 params
URL params:
:client_id -- our :api-key
:state -- the state token
:response_type -- "code"
:redirect_uri (optional) -- the service :callback, if configured
:scope (optional) -- the service :scope, if configured
other params given by extra-params
jwt-read
(jwt-read fields)
Decodes a URL-encoded JSON Web Token and returns its body.
Does not validate the JWT--use only if the JWT is trusted.
remove-nils
(remove-nils m)
Remove nil keys from a map.
v2-json-parser
(v2-json-parser response-stream)
Parser for use with do-request-access. Reads a JSON-encoded response stream.