Ltix.AdvantageService behaviour (Ltix v0.2.0)

Copy Markdown View Source

Behaviour for LTI Advantage service modules.

Each Advantage service implements this behaviour to describe its endpoint type and required OAuth scopes. Ltix.OAuth uses these callbacks to read endpoints from launch claims, validate endpoints, derive scopes, and build authenticated clients for any service.

Implementing a custom service

defmodule MyApp.ProctorService do
  @behaviour Ltix.AdvantageService

  @impl true
  def endpoint_from_claims(%Ltix.LaunchClaims{} = _claims), do: :error

  @impl true
  def validate_endpoint(%MyApp.ProctorEndpoint{}), do: :ok

  def validate_endpoint(_),
    do: {:error, Ltix.Errors.Invalid.InvalidEndpoint.exception(service: __MODULE__)}

  @impl true
  def scopes(%MyApp.ProctorEndpoint{}),
    do: ["https://example.com/scope/proctoring"]
end

Send the service's requests with Ltix.OAuth.Client.request/3.

Summary

Callbacks

Extract the service's endpoint from launch claims, or return :error when the launch has none.

Return the OAuth scope URIs required by this endpoint.

Validate that the given value is a valid endpoint for this service.

Callbacks

endpoint_from_claims(t)

@callback endpoint_from_claims(Ltix.LaunchClaims.t()) :: {:ok, term()} | :error

Extract the service's endpoint from launch claims, or return :error when the launch has none.

scopes(term)

@callback scopes(term()) :: [String.t()]

Return the OAuth scope URIs required by this endpoint.

validate_endpoint(term)

@callback validate_endpoint(term()) :: :ok | {:error, Exception.t()}

Validate that the given value is a valid endpoint for this service.