MpesaElixir.AuthServer (MpesaElixir v0.2.1)
A GenServer implementation that manages Mpesa API authentication tokens.
This server is responsible for:
- Obtaining an access token from the Mpesa API during initialization
- Storing the token in an ETS table for quick access
- Automatically refreshing the token before it expires
- Providing a function to retrieve the current token
Usage
The AuthServer should be added to your application's supervision tree:
children = [
# ... other children
MpesaElixir.AuthServer
]
Supervisor.start_link(children, strategy: :one_for_one)
You can then retrieve the current access token when needed:
token = MpesaElixir.AuthServer.get_token()
Configuration
The server requires the following configuration parameters:
config :mpesa_elixir,
consumer_key: "your_consumer_key",
consumer_secret: "your_consumer_secret"
Implementation details
- Uses ETS for token storage, with a named table
:token_store
- Automatically refreshes tokens 100 seconds before expiration
- Gracefully shuts down if token retrieval fails
Summary
Functions
Returns a specification to start this module under a supervisor.