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
Activates a previously deactivated provider.
Examples
iex> activate_provider(provider)
{:ok, %Provider{}}
Returns an %Ecto.Changeset{} for tracking provider changes.
Examples
iex> change_provider(provider)
%Ecto.Changeset{data: %Provider{}}
Counts active providers.
Examples
iex> count_providers()
5
Creates a provider.
Examples
iex> create_provider(%{name: "custom", display_name: "Custom OAuth"})
{:ok, %Provider{}}
iex> create_provider(%{})
{:error, %Ecto.Changeset{}}
Creates a provider from Nango configuration.
Examples
iex> create_provider_from_nango("github", nango_config, client_id: "abc", client_secret: "xyz")
{:ok, %Provider{}}
Soft deletes a provider by setting active to false.
Examples
iex> delete_provider(provider)
{:ok, %Provider{}}
iex> delete_provider(provider)
{:error, %Ecto.Changeset{}}
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: "..."}}
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}
Gets a single provider by ID.
Returns {:ok, provider} if found, {:error, :not_found} if not found.
Gets providers by auth mode (OAUTH2, API_KEY, etc.).
Examples
iex> get_providers_by_auth_mode("OAUTH2")
[%Provider{}, ...]
Returns all providers including inactive ones.
Examples
iex> list_all_providers()
[%Provider{}, ...]
Returns the list of active providers.
Examples
iex> list_providers()
[%Provider{}, ...]
Searches providers by name or display name.
Examples
iex> search_providers("git")
[%Provider{name: "github"}, %Provider{name: "gitlab"}]
Updates a provider.
Examples
iex> update_provider(provider, %{display_name: "New Name"})
{:ok, %Provider{}}
iex> update_provider(provider, %{name: nil})
{:error, %Ecto.Changeset{}}
Validates provider configuration without saving.
Examples
iex> validate_provider_config(%{name: "test", config: config_json})
{:ok, changeset}
iex> validate_provider_config(%{})
{:error, changeset}