WardrikOAuth.Request (wardrik_oauth v0.1.0-rc.1)

Copy Markdown

Sends a flow's requests to an authorization server.

Each function takes Req options, plus :check, a function called on each URL first. URLs must be https, or http on localhost.

Summary

Functions

Gets JSON from url.

Posts form to url as provider's client. Returns the status and the JSON body.

Posts body to url as JSON. Returns the status and the JSON body.

Puts value in form under key, unless it's nil or "".

Returns an OAuth error response as {:token_refused, error, description}.

Functions

get_json(url, req_options)

@spec get_json(String.t(), keyword()) :: {:ok, map()} | {:error, term()}

Gets JSON from url.

post_as(url, provider, form, req_options)

@spec post_as(String.t(), WardrikOAuth.Provider.t(), map(), keyword()) ::
  {:ok, pos_integer(), map()} | {:error, term()}

Posts form to url as provider's client. Returns the status and the JSON body.

The client secret goes in the form, or in an HTTP Basic header if client_auth is :basic.

post_json(url, body, req_options)

@spec post_json(String.t(), map(), keyword()) ::
  {:ok, pos_integer(), map()} | {:error, term()}

Posts body to url as JSON. Returns the status and the JSON body.

present(form, key, value)

@spec present(map(), String.t(), term()) :: map()

Puts value in form under key, unless it's nil or "".

refusal(status, body)

@spec refusal(pos_integer(), map()) :: {:token_refused, String.t(), String.t() | nil}

Returns an OAuth error response as {:token_refused, error, description}.