PowAssent v0.4.5 PowAssent.Plug View Source

Plug helper methods.

If you wish to configure PowAssent through the Pow plug interface rather than environment config, please add PowAssent config with :pow_assent config:

plug Pow.Plug.Session,
  repo: MyApp.Repo,
  user: MyApp.User,
  pow_assent: [
    http_adapter: PowAssent.HTTPAdapter.Mint,
    json_library: Poison,
    user_identities_context: MyApp.UserIdentities
  ]

Link to this section Summary

Functions

Authenticates a user with provider and provider user params.

Calls the authorize_url method for the provider strategy.

Lists available providers for connection.

Calls the callback method for the provider strategy.

Create a user with the provider and provider user params.

Deletes the associated user identity for the current user and provider.

Lists associated providers for the user.

Will upsert identity for the current user.

Link to this section Functions

Link to this function

authenticate(conn, map)

View Source
authenticate(Plug.Conn.t(), map()) ::
  {:ok, Plug.Conn.t()} | {:error, Plug.Conn.t()}

Authenticates a user with provider and provider user params.

If successful, a new session will be created.

Link to this function

authorize_url(conn, provider, redirect_uri)

View Source
authorize_url(Plug.Conn.t(), binary(), binary()) ::
  {:ok, binary(), Plug.Conn.t()} | {:error, any(), Plug.Conn.t()}

Calls the authorize_url method for the provider strategy.

A generated authorization URL will be returned. If :session_params is returned from the provider, it'll be added to the connection as private key :pow_assent_session_params.

If :nonce is set to true in the provider configuration, a randomly generated nonce will be added to the configuration.

Link to this function

available_providers(conn)

View Source
available_providers(Plug.Conn.t() | PowAssent.Config.t()) :: [atom()]

Lists available providers for connection.

Link to this function

callback(conn, provider, params, redirect_uri)

View Source
callback(Plug.Conn.t(), binary(), map(), binary()) ::
  {:ok, map(), map(), Plug.Conn.t()} | {:error, any(), Plug.Conn.t()}

Calls the callback method for the provider strategy.

Returns the user identity params and user params fetched from the provider.

:session_params will be added to the provider config if :pow_assent_session_params is present as a private key in the connection.

Link to this function

create_user(conn, user_identity_params, user_params, user_id_params \\ nil)

View Source
create_user(Plug.Conn.t(), map(), map(), map() | nil) ::
  {:ok, map(), Plug.Conn.t()}
  | {:error,
     {:bound_to_different_user | :invalid_user_id_field, map()} | map(),
     Plug.Conn.t()}

Create a user with the provider and provider user params.

If successful, a new session will be created.

Link to this function

delete_identity(conn, provider)

View Source
delete_identity(Plug.Conn.t(), binary()) ::
  {:ok, map(), Plug.Conn.t()} | {:error, {:no_password, map()}, Plug.Conn.t()}

Deletes the associated user identity for the current user and provider.

Link to this function

providers_for_current_user(conn)

View Source
providers_for_current_user(Plug.Conn.t()) :: [atom()]

Lists associated providers for the user.

Link to this function

upsert_identity(conn, user_identity_params)

View Source
upsert_identity(Plug.Conn.t(), map()) ::
  {:ok, map(), Plug.Conn.t()}
  | {:error, {:bound_to_different_user, map()} | map(), Plug.Conn.t()}

Will upsert identity for the current user.

If successful, a new session will be created.