View Source PurpleAuthClient
An Elixir client for my Purple Auth microservice.
configuration
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
Routes Covered
otp-request
/otp/request/
Start otp authentication flow with server.
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :otp)
:ok
magic-request
/magic/request/
> PurpleAuthClient.start_authentication("rickhenry@rickhenry.dev", :magic)
:ok
otp-confirm
/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
/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
/token/refresh/
Request a new ID Token from the server using a refresh token
> PurpleAuthClient.refresh("refreshtoken")
{:ok, "newidtoken"}
local-verification
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
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