PurpleAuthClient
An Elixir client for my Purple Auth microservice.
Configuration
# config/config.exs
import Config
config :purple_auth_client,
host: "http://purpleauth.com", # or wherever you're hosting it
app_id: "[app id obtained from purple auth portal]",
api_key: "[api key obtained from purple auth portal]"Routes Covered
/otp/request/
Start otp authentication flow with server.
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :otp)
:ok/magic/request/
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :magic)
:ok/otp/confirm/
Complete authentication with email and generated code.
> PurpleAuthClient.submit_code("rickhenry@rickhenry.dev", "123456")
{:ok, %{id_token: "tokenfromserver", refresh_token: "refreshtokenfromserver"}}
/token/verify/
Send idToken to server for verification. This is not recommended as local verification will be significantly faster after the first time.
> PurpleAuthClient.verify_token_remote("idtoken")
{:ok, claims}/token/refresh/
Request a new ID Token from the server using a refresh token
> PurpleAuthClient.refresh("refreshtoken")
{:ok, "newidtoken"}Local Verification
Verify and decode an ID Token on directly in the app without having to
call out every time. It's much faster because the keys are cached in an :ets table
> PurpleAuthClient.verify("idtoken")
{:ok, claims}
> PurpleAuthClient.verify("invalididtoken")
{:error, :signature_error}Installation
If available in Hex, the package can be installed
by adding purple_auth_client to your list of dependencies in mix.exs:
def deps do
[
{:purple_auth_client, "~> 0.1.0"}
]
end