MPX v0.1.9 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
Calls the authenticated endpoint with the given token to determine if the token is still valid
Types
authentication_opts :: [username: String.t, password: String.t, client_id: String.t, client_secret: String.t]
Functions
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}
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"
Specs
clear :: :ok
Clears any cached authentication tokens
Examples
iex> Mpx.Authentication.clear()
:ok
Specs
invalidate_token(String.t) :: :ok | :error
Invalidates a token, so the next call to authenticate will go to the server
Specs
valid_token?(String.t) :: true | false
Calls the authenticated endpoint with the given token to determine if the token is still valid.