WardrikWeb.Connections behaviour (wardrik_web v0.1.0-rc.1)

Copy Markdown

Gives the Connections page its data: the signed-in person's accounts on other services.

Agents call those services as the person who connected the account. Implement this behaviour to list, connect and disconnect accounts, then turn the page on in the router:

wardrik_dashboard "/wardrik",
  resolver: {MyAppWeb.WardrikResolver, []},
  settings: [connections: {MyApp.WardrikConnections, []}]

Connections

list/2 returns maps with string keys:

  • "provider" - required. The service's name.
  • "connected" - true once the account is connected.
  • "signing_in" - true while a sign-in is in progress.

Signing in

connect/3 returns {:ok, connecting}, where connecting is a map with "provider" and either "connected" => true or an "authorization":

  • %{"url" => url} - the page opens url. The service then shows a code, and the person enters it on the page. The page calls pair/4 with the code.
  • %{"url" => url, "code" => code} - the person enters code at url. The page refreshes until the account is connected.

Summary

Types

An error the page shows.

Your options, as given in the router.

Callbacks

Starts connecting the person's account on provider.

Disconnects the person's account on provider.

Returns the person's connections, connected or not.

Finishes connecting with the code the service showed.

Types

error()

@type error() :: {:error, Wardrik.Error.t() | String.t()}

An error the page shows.

opts()

@type opts() :: term()

Your options, as given in the router.

Callbacks

connect(t, provider, opts)

@callback connect(Wardrik.Scope.t(), provider :: String.t(), opts()) ::
  {:ok, map()} | error()

Starts connecting the person's account on provider.

disconnect(t, provider, opts)

@callback disconnect(Wardrik.Scope.t(), provider :: String.t(), opts()) :: :ok | error()

Disconnects the person's account on provider.

list(t, opts)

@callback list(Wardrik.Scope.t(), opts()) :: {:ok, [map()]} | error()

Returns the person's connections, connected or not.

pair(t, provider, code, opts)

@callback pair(Wardrik.Scope.t(), provider :: String.t(), code :: String.t(), opts()) ::
  :ok | error()

Finishes connecting with the code the service showed.