FdsnPlugs
Collection of plugs related to FDSN webservices.
Installation
If available in Hex, the package can be installed
by adding fdsn_plugs to your list of dependencies in mix.exs:
def deps do
[
{:fdsn_plugs, "~> 0.9.0"}
]
end
Usage
This module provides two supersets of plugs: FdsnDataselectPlugs and
FdsnAvailabilityPlugs to implement dataselect and availability web services.
Phoenix
Add the plug collection to your pipeline:
pipeline :fdsn do
plug :accepts, ["json", "text", "mseed"]
plug FdsnDataselectPlugs
end
JWT authentication
FdsnPlugs.JWTAuthentication is included in both pipeline supersets. It
authenticates requests via JWT bearer tokens, supporting multiple token
authorities.
1. Start one FdsnPlugs.JwkStrategy per authority in your supervision tree
Each strategy fetches and caches JWKS signing keys from the given URL.
children = [
{FdsnPlugs.JwkStrategy,
name: :eida,
jwks_url: "https://geofon.gfz.de/eas2/jwk",
time_interval: 600_000,
first_fetch_sync: true},
{FdsnPlugs.JwkStrategy,
name: :other_authority,
jwks_url: "https://auth.example.com/jwks",
first_fetch_sync: true}
]
first_fetch_sync must be set to true.
2. Configure which authorities the plug should try
Via application config:
config :fdsn_plugs, :jwt_authorities, [:eida, :other_authority]
Or inline in a custom pipeline:
plug FdsnPlugs.JWTAuthentication, authorities: [:eida, :other_authority]
How it works
- If
conn.assigns.useris already set (e.g. HTTP Digest auth from your application), the plug passes through. - If no
Authorizationheader is present, the plug passes through. - On a
Bearer <token>header, each authority is tried in order. - On success, all token claims are stored in
conn.assigns.jwt_claimsand theemailclaim is stored inconn.assigns.user. - If no authority validates the token, a 401 response is returned with a
WWW-Authenticateheader explaining the reason.