View Source Lightning.OauthClients (Lightning v2.10.4)

Manages operations for OAuth clients within the Lightning application, providing functions to create, retrieve, update, and delete OAuth clients, as well as managing their associations with projects and handling audit trails for changes.

Summary

Functions

Prepares a changeset for creating or updating an OAuth client.

Creates a new OAuth client with the specified attributes.

Deletes an OAuth client and all associated data.

Retrieves a single OAuth client by its ID, raising an error if not found.

Retrieves all OAuth clients based on the given context, either a Project or a User.

Updates an existing OAuth client with the specified attributes.

Functions

Link to this function

change_client(client, attrs \\ %{})

View Source

Prepares a changeset for creating or updating an OAuth client.

Parameters

  • client: The OAuth client struct.
  • attrs: Attributes to update in the client.

Returns

  • An Ecto.Changeset struct for the OAuth client.

Examples

iex> change_client(%OauthClient{}, %{name: "New Client"})
%Ecto.Changeset{...}
Link to this function

create_client(attrs \\ %{})

View Source

Creates a new OAuth client with the specified attributes.

Parameters

  • attrs: Map containing attributes for the new OAuth client. Required fields: name, authorization_endpoint, token_endpoint, revocation_endpoint, client_id, client_secret.

Returns

  • {:ok, oauth_client} if the client is created successfully.
  • {:error, changeset} if there is an error during creation due to validation failures or database issues.

Examples

iex> create_client(%{name: "New Client"}) {:ok, %OauthClient{}}

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

Deletes an OAuth client and all associated data.

Parameters

  • client: The OauthClient to delete.

Returns

  • A tuple {:ok, oauth_client} if deletion is successful.
  • A tuple {:error, changeset} if deletion fails.

Examples

iex> delete_client(client)
{:ok, %OauthClient{}}

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

Retrieves a single OAuth client by its ID, raising an error if not found.

Parameters

  • id: The ID of the OAuth client to retrieve.

Returns

  • The OAuth client struct.

Raises

  • Ecto.NoResultsError if the OAuth client does not exist.

Examples

iex> get_client!(123)
%OauthClient{}

iex> get_client!(456)
** (Ecto.NoResultsError)

Retrieves all OAuth clients based on the given context, either a Project or a User.

Parameters

  • context: The Project or User struct to retrieve OAuth clients for.

Returns

  • A list of OAuth clients associated with the given Project or created by the given User.

Examples

When given a Project:

iex> list_clients(%Project{id: 1})
[%OauthClient{project_id: 1}, %OauthClient{project_id: 1}]

When given a User:

iex> list_clients(%User{id: 123})
[%OauthClient{user_id: 123}, %OauthClient{user_id: 123}]
Link to this function

update_client(client, attrs)

View Source

Updates an existing OAuth client with the specified attributes.

Parameters

  • client: The existing OauthClient to update.
  • attrs: A map of attributes to update.

Returns

  • A tuple {:ok, oauth_client} if update is successful.
  • A tuple {:error, changeset} if update fails.

Examples

iex> update_client(client, %{field: new_value})
{:ok, %OauthClient{}}

iex> update_client(client, %{field: bad_value})
{:error, %Ecto.Changeset{}}