# `LightningWeb.OauthCredentialHelper`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning_web/oauth_credential_helper.ex#L1)

A set of helper functions to encodes state and coordinate OAuth callbacks
back to a LiveView component.

# `broadcast`

# `broadcast_forward`

Broadcast a message specifically for forwarding a message to a component.
It expects a `subscription_id`, the module of the component and `opts`
being a keyword list containing an `:id` key of the specific component.

See: `Phoenix.LiveView.send_update/3` for more info.

A corresponding LiveView (that is subscribed) is expected to have a matching
`handle_info/2` that looks like this:

```
def handle_info({:forward, mod, opts}, socket) do
  send_update(mod, opts)
  {:noreply, socket}
end
```

# `build_state`

Encode and encrypt the callback data which will be sent so a provider
as the `state` key in the request.

The values are:

- `subscription_id`
  The same ID used to subscribe.
- The component module
  The LiveView component that is going to receive update
- The component id
  The ID of the component
- The current tab (environment name)
  Which environment/tab is being authorized

# `decode_state`

# `subscribe`

Subscribe to the `oauth_credential` topic.
It expects the a unique ID for the topic, usually the LiveView's `socket.id`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
