An Elixir client for my Purple Auth microservice.
# 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]"
Start otp authentication flow with server.
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :otp)
:ok
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :magic)
:ok
Complete authentication with email and generated code.
> PurpleAuthClient.submit_code("rickhenry@rickhenry.dev", "123456")
{:ok, %{id_token: "tokenfromserver", refresh_token: "refreshtokenfromserver"}}
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}
Request a new ID Token from the server using a refresh token
> PurpleAuthClient.refresh("refreshtoken")
{:ok, "newidtoken"}
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}
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