Tango.Provider (tango v0.1.2)

Copy Markdown View Source

Context module for OAuth provider configuration management.

Provides CRUD operations for OAuth providers with support for Nango catalog integration, validation, and credential management.

Summary

Functions

Activates a previously deactivated provider.

Returns an %Ecto.Changeset{} for tracking provider changes.

Counts active providers.

Creates a provider.

Creates a provider from Nango configuration.

Soft deletes a provider by setting active to false.

Gets OAuth client configuration for a provider.

Gets a single provider by slug.

Gets a single provider by ID.

Gets providers by auth mode (OAUTH2, API_KEY, etc.).

Returns all providers including inactive ones.

Returns the list of active providers.

Searches providers by name or display name.

Updates a provider.

Validates provider configuration without saving.

Functions

activate_provider(provider)

Activates a previously deactivated provider.

Examples

iex> activate_provider(provider)
{:ok, %Provider{}}

change_provider(provider, attrs \\ %{})

Returns an %Ecto.Changeset{} for tracking provider changes.

Examples

iex> change_provider(provider)
%Ecto.Changeset{data: %Provider{}}

count_providers()

Counts active providers.

Examples

iex> count_providers()
5

create_provider(attrs \\ %{})

Creates a provider.

Examples

iex> create_provider(%{name: "custom", display_name: "Custom OAuth"})
{:ok, %Provider{}}

iex> create_provider(%{})
{:error, %Ecto.Changeset{}}

create_provider_from_nango(name, nango_config, opts \\ [])

Creates a provider from Nango configuration.

Examples

iex> create_provider_from_nango("github", nango_config, client_id: "abc", client_secret: "xyz")
{:ok, %Provider{}}

delete_provider(provider)

Soft deletes a provider by setting active to false.

Examples

iex> delete_provider(provider)
{:ok, %Provider{}}

iex> delete_provider(provider)
{:error, %Ecto.Changeset{}}

get_oauth_client(provider_name)

Gets OAuth client configuration for a provider.

Returns the OAuth client credentials and endpoints needed for authorization flow.

Examples

iex> get_oauth_client("github")
{:ok, %{client_id: "abc", client_secret: "xyz", auth_url: "...", token_url: "..."}}

get_provider(slug)

Gets a single provider by slug.

Returns {:ok, provider} if found, {:error, :not_found} if not found.

Examples

iex> get_provider("github")
{:ok, %Provider{}}

iex> get_provider("nonexistent")
{:error, :not_found}

get_provider_by_id(id)

Gets a single provider by ID.

Returns {:ok, provider} if found, {:error, :not_found} if not found.

get_providers_by_auth_mode(auth_mode)

Gets providers by auth mode (OAUTH2, API_KEY, etc.).

Examples

iex> get_providers_by_auth_mode("OAUTH2")
[%Provider{}, ...]

list_all_providers()

Returns all providers including inactive ones.

Examples

iex> list_all_providers()
[%Provider{}, ...]

list_providers()

Returns the list of active providers.

Examples

iex> list_providers()
[%Provider{}, ...]

search_providers(search_term)

Searches providers by name or display name.

Examples

iex> search_providers("git")
[%Provider{name: "github"}, %Provider{name: "gitlab"}]

update_provider(provider, attrs)

Updates a provider.

Examples

iex> update_provider(provider, %{display_name: "New Name"})
{:ok, %Provider{}}

iex> update_provider(provider, %{name: nil})
{:error, %Ecto.Changeset{}}

validate_provider_config(attrs)

Validates provider configuration without saving.

Examples

iex> validate_provider_config(%{name: "test", config: config_json})
{:ok, changeset}

iex> validate_provider_config(%{})
{:error, changeset}