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"-trueonce the account is connected."signing_in"-truewhile 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 opensurl. The service then shows a code, and the person enters it on the page. The page callspair/4with the code.%{"url" => url, "code" => code}- the person enterscodeaturl. The page refreshes until the account is connected.
Summary
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
@type error() :: {:error, Wardrik.Error.t() | String.t()}
An error the page shows.
@type opts() :: term()
Your options, as given in the router.
Callbacks
@callback connect(Wardrik.Scope.t(), provider :: String.t(), opts()) :: {:ok, map()} | error()
Starts connecting the person's account on provider.
@callback disconnect(Wardrik.Scope.t(), provider :: String.t(), opts()) :: :ok | error()
Disconnects the person's account on provider.
@callback list(Wardrik.Scope.t(), opts()) :: {:ok, [map()]} | error()
Returns the person's connections, connected or not.
@callback pair(Wardrik.Scope.t(), provider :: String.t(), code :: String.t(), opts()) :: :ok | error()
Finishes connecting with the code the service showed.