MPX v0.1.8 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.

This also supports authenticating as a Client. For this case, the configuration is used to authenticate as the default user whose token we use to get the client details from the Clients table. Once we have the client_secret, we then attempt to authenticate as the client using the grant_type of client_credentials.

Summary

Functions

Authenticate with Ministry Platform

Uses the default authentication token to get a token for an api client

Clears any cached authentication tokens

Invalidates a token, so the next call to authenticate will go to the server

Types

authentication_opts :: [username: String.t, password: String.t, client_id: String.t, client_secret: String.t]

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}

authenticate_client(client_id)

Specs

authenticate_client(String.t) ::
  {:ok, String.t} |
  {:error, String.t}

Uses the default authentication token to get a token for an api client.

Assumes that the authentication parameters are set in the config:

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"
clear()

Specs

clear :: :ok

Clears any cached authentication tokens

Examples

iex> Mpx.Authentication.clear()
:ok
invalidate_token(client_id)

Specs

invalidate_token(String.t) :: :ok | :error

Invalidates a token, so the next call to authenticate will go to the server