MPX v0.1.4 Mpx.Authentication

Handles all aspects of authenticating with the Ministry Platform API.

Ministry Platform expects a username and password AND a clientId and Client Secret that are set in the Ministy Platform Api Clients table. We send these parameters along with the grant type of “password” to the server and recieve back a token and refresh token that needs to be sent on subsequent requests to the MP.

Summary

Functions

Authenticate with Ministry Platform

Clears any cached authentication tokens

Types

authentication_opts :: [username: String.t, password: String.t, client_id: String.t, client_secret: String.t]
http :: {atom, map | list} | {atom, term}

Functions

authenticate(opts \\ [])

Specs

authenticate(authentication_opts | nil) ::
  {:ok, String.t} |
  {:error, String.t}

Authenticate with Ministry Platform.

Takes a keyword list of options in the shape:

[ username: "mp-username",
  password: "mp-password",
  client_id: "mp-client-id",
  client_secret: "mp-client-secret" ]

If keyword options are not passed in, defaults to configuration parameters:

mpx, mp_username: "mp-username",
     mp_password: System.get_env("MP_PASSWORD"),
     mp_client_id: {:system, "MP_CLIENT_ID"},
     mp_client_secret: "mp-client-secret"

Returns {:ok, token} where token can be used in subsequent calls to the API that need to be authenticated or {:error, reason}

clear()

Specs

clear :: :ok

Clears any cached authentication tokens

Examples

iex> Mpx.Authentication.clear()
:ok