MapkitJS

Elixir helper library for generating MapKit JS authorization tokens.

It is designed for simple server-side token issuance for browser clients that call mapkit.init/1.

Installation

Add to your mix.exs:

defp deps do
[
{:mapkit_js, "~> 0.3.0"}
]
end

Configuration

config :mapkit_js,
team_id: System.get_env("APPLE_TEAM_ID"),
key_id: System.get_env("MAPKIT_KEY_ID"),
private_key_path: System.get_env("MAPKIT_PRIVATE_KEY_PATH"),
origin: System.get_env("MAPKIT_ORIGIN")

Supported options:

Quick Start

# Generate a token
{:ok, token} = MapkitJS.token()
# Override origin per call
{:ok, token} = MapkitJS.generate_token(origin: "https://example.com")
# Build a payload for a browser-side authorization callback
{:ok, payload} = MapkitJS.authorization_callback_payload()

Browser Usage

mapkit.init({
authorizationCallback: async function(done) {
const response = await fetch("/token")
const payload = await response.json()
done(payload.token)
}
})

Local Demo

This project includes a local demo page and token server.

Run it with:

cd mapkit_js
source .env && elixir demo_server.exs

Then open:

http://127.0.0.1:4002

Live Smoke Test

cd mapkit_js
source .env && elixir test_live.exs

Notes

License

MIT