Ltix.Registerable protocol (Ltix v0.2.0)

Copy Markdown View Source

Protocol for converting your registration struct to an Ltix.Registration.

Implement it for your registration struct, and your storage adapter can return that struct. Ltix passes your struct to the other Ltix.StorageAdapter callbacks, and the Ltix.LaunchContext and Ltix.OAuth.Client have it.

defmodule MyApp.PlatformRegistration do
  defstruct [:id, :tenant_id, :issuer, :client_id,
             :auth_endpoint, :jwks_uri, :token_endpoint]

  defimpl Ltix.Registerable do
    def to_registration(reg) do
      Ltix.Registration.new(%{
        issuer: reg.issuer,
        client_id: reg.client_id,
        auth_endpoint: reg.auth_endpoint,
        jwks_uri: reg.jwks_uri,
        token_endpoint: reg.token_endpoint
      })
    end
  end
end

Ltix.Registration implements this protocol, so your storage adapter can also return a %Registration{}. Login and launch return the same error as Ltix.Registration.new/1 for an invalid one.

Summary

Types

t()

All the types that implement this protocol.

Functions

Return the Ltix.Registration for the given struct.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

to_registration(source)

@spec to_registration(t()) :: {:ok, Ltix.Registration.t()} | {:error, Exception.t()}

Return the Ltix.Registration for the given struct.

Build it with Ltix.Registration.new/1, which validates the fields.