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-extract-code

(do-extract-code our-state {params :params, :as req} state-fn code-fn error-fn)
Helper fn for implementors to extract an auth code from a Ring request.
Looks for the params in the givne Ring request.
Returns the found auth code, nil if no state or code was found,
or throws an exception if an error or token mismatch were found.

our-state -- the state token in the record
req -- the request
state-fn -- finds the state token in the params
code-fn -- finds the auth code in the params
error-fn -- finds the error in the params

In standard OAuth v2, state-fn, code-fn and error-fn are
:state, :code and :error respectively.

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-form-parser

(v2-form-parser response-stream)
Parser for use with do-request-access. Reads a form-encoded response stream.

v2-json-parser

(v2-json-parser response-stream)
Parser for use with do-request-access. Reads a JSON-encoded response stream.