CPub.Web.Authorization (CPub v0.3.0) View Source

An OAuth 2.0 Authorization.

An CPub.Web.Authorization.Authorization includes a code that can be used to obtain a CPub.Web.Authorization.Token. The token can be used to access resources. The Authorization can only be used once and is valid for only 10 minutes after creation.

The CPub.Web.Authorization.Authorization remains in the database and can be reused to refresh a token (see https://tools.ietf.org/html/rfc6749#section-6) until it is explicitly revoked (deleted). On deletion all CPub.Web.Authorization.Tokens that were created based on the Authorization are revoked (deleted).

Protected routes have a authorization assigned (see CPub.Web.Authorization.AuthorizationPlug).

Link to this section Summary

Functions

Create a new Authorization for the given user and scope without associating a client.

Create a new Authorization for the given user, client and scope.

Returns true if the Authorization has expired (has been created more than 10 minutes ago).

Get an authorization by id.

Get an authorization by the code.

Get an authorization by the refresh token.

Mark the authorization code as used.

Returns the number of seconds the Authorization code is valid for after initial creation.

Link to this section Types

Specs

t() :: %CPub.Web.Authorization{
  __meta__: term(),
  authorization_code: String.t(),
  client: String.t(),
  code_used: bool(),
  created_at: NaiveDateTime.t(),
  id: String.t(),
  refresh_token: String.t(),
  scope: [atom()],
  user: String.t()
}

Link to this section Functions

Specs

create(CPub.User.t(), [String.t()]) :: {:ok, t()} | {:error, any()}

Create a new Authorization for the given user and scope without associating a client.

Link to this function

create(user, client, scope)

View Source

Specs

create(CPub.User.t(), CPub.Web.Authorization.Client.t(), [String.t() | atom()]) ::
  {:ok, t()} | {:error, any()}

Create a new Authorization for the given user, client and scope.

Link to this function

expired?(authentication)

View Source

Specs

expired?(t()) :: bool()

Returns true if the Authorization has expired (has been created more than 10 minutes ago).

Specs

get(String.t()) :: {:ok, t()} | {:error, any()}

Get an authorization by id.

Specs

get_by_code(String.t()) :: {:ok, t()} | {:error, any()}

Get an authorization by the code.

Link to this function

get_by_refresh_token(token)

View Source

Specs

get_by_refresh_token(String.t()) :: {:ok, t()} | {:error, any()}

Get an authorization by the refresh token.

Link to this function

use_code!(authorization)

View Source

Specs

use_code!(t()) :: {:ok, t()} | {:error, any()}

Mark the authorization code as used.

Specs

valid_for() :: non_neg_integer()

Returns the number of seconds the Authorization code is valid for after initial creation.