ExOauth2Provider v0.4.2 ExOauth2Provider.OauthAccessTokens View Source

Ecto schema for oauth access tokens

Link to this section Summary

Functions

Creates an access token

Filter expired data

Filter revoked data

Gets all authorized access tokens for resource owner

Gets an old access token by previous refresh token

Gets an access token by the refresh token

Gets an access token by the refresh token belonging to an application

Gets a single access token

Gets the most recent, acccessible, matching access token for a resource owner

Gets existing access token or creates a new one with supplied attributes

Checks if an access token can be accessed

Checks if data has expired

Checks if data has been revoked

Same as revoke/1 but raises error

Revoke data

Revokes token with refresh_token equal to previous_refresh_token and clears :previous_refresh_token attribute

Link to this section Functions

Link to this function create_token(owner, attrs \\ %{}) View Source
create_token(Ecto.Schema.t(), map()) ::
  {:ok, ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()}
  | {:error, Ecto.Changeset.t()}

Creates an access token.

Examples

iex> create_token(application, %{scopes: "read write"})
{:ok, %OauthAccessToken{}}

iex> create_token(resource_owner, %{application: application, scopes: "read write"})
{:ok, %OauthAccessToken{}}

iex> create_token(resource_owner, %{scopes: "read write"})
{:ok, %OauthAccessToken{}}

iex> create_token(resource_owner, %{expires_in: "invalid"})
{:error, %Ecto.Changeset{}}
Link to this function filter_expired(data) View Source
filter_expired(Ecto.Schema.t()) :: Ecto.Schema.t() | nil

Filter expired data.

Examples

iex> filter_expired(%Data{expires_in: 7200, inserted_at: ~N[2017-04-04 19:21:22.292762], ...}}
%Data{}

iex> filter_expired(%Data{expires_in: 10, inserted_at: ~N[2017-04-04 19:21:22.292762], ...}}
nil
Link to this function filter_revoked(data) View Source
filter_revoked(Ecto.Schema.t()) :: Ecto.Schema.t() | nil

Filter revoked data.

Examples

iex> filter_revoked(%Data{revoked_at: nil, ...}}
%Data{}

iex> filter_revoked(%Data{revoked_at: ~N[2017-04-04 19:21:22.292762], ...}}
nil
Link to this function get_authorized_tokens_for(resource_owner) View Source
get_authorized_tokens_for(Ecto.Schema.t()) :: [
  ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()
]

Gets all authorized access tokens for resource owner.

Examples

iex> get_authorized_tokens_for(resource_owner)
[%OauthAccessToken{}, ...]
Link to this function get_by_previous_refresh_token_for(access_token) View Source
get_by_previous_refresh_token_for(
  ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()
) :: ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil

Gets an old access token by previous refresh token.

Examples

iex> get_by_previous_refresh_token_for(new_access_token)
%OauthAccessToken{}

iex> get_by_previous_refresh_token_for(new_access_token)
nil
Link to this function get_by_refresh_token(refresh_token) View Source
get_by_refresh_token(binary()) ::
  ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil

Gets an access token by the refresh token.

Examples

iex> get_by_refresh_token("c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d")
%OauthAccessToken{}

iex> get_by_refresh_token("75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc")
nil
Link to this function get_by_refresh_token_for(application, refresh_token) View Source
get_by_refresh_token_for(
  ExOauth2Provider.OauthApplications.OauthApplication.t(),
  binary()
) :: ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil

Gets an access token by the refresh token belonging to an application.

Examples

iex> get_by_refresh_token_for(application, "c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d")
%OauthAccessToken{}

iex> get_by_refresh_token_for(application, "75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc")
nil
Link to this function get_by_token(token) View Source
get_by_token(binary()) ::
  ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil

Gets a single access token.

Examples

iex> get_by_token("c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d")
%OauthAccessToken{}

iex> get_by_token("75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc")
nil
Link to this function get_matching_token_for(resource_owner, application, scopes) View Source
get_matching_token_for(
  nil,
  ExOauth2Provider.OauthApplications.OauthApplication.t(),
  binary()
) :: ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil
get_matching_token_for(
  Ecto.Schema.t(),
  ExOauth2Provider.OauthApplications.OauthApplication.t() | nil,
  binary()
) :: ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil

Gets the most recent, acccessible, matching access token for a resource owner.

Examples

iex> get_matching_token_for(resource_owner, application, "read write")
%OauthAccessToken{}

iex> get_matching_token_for(resource_owner, application, "read invalid")
nil
Link to this function get_or_create_token(application, scopes, attrs) View Source
get_or_create_token(
  ExOauth2Provider.OauthApplications.OauthApplication.t(),
  binary() | nil,
  map()
) ::
  {:ok, ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()}
  | {:error, Ecto.Changeset.t()}

Gets existing access token or creates a new one with supplied attributes.

Examples

iex> get_or_create_token(application, scopes, attrs)
{:ok, %OauthAccessToken{}}

iex> get_or_create_token(user, application, scopes, attrs)
{:ok, %OauthAccessToken{}}

iex> get_or_create_token(user, application, scopes, attrs)
{:error, %Ecto.Changeset{}}
Link to this function get_or_create_token(resource_owner, application, scopes, attrs) View Source
get_or_create_token(
  Ecto.Schema.t(),
  ExOauth2Provider.OauthApplications.OauthApplication.t() | nil,
  binary() | nil,
  map()
) ::
  {:ok, ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()}
  | {:error, Ecto.Changeset.t()}
Link to this function is_accessible?(token) View Source
is_accessible?(ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t() | nil) ::
  boolean()

Checks if an access token can be accessed.

Examples

iex> is_accessible?(token)
true

iex> is_accessible?(inaccessible_token)
false
Link to this function is_expired?(arg1) View Source
is_expired?(Ecto.Schema.t() | nil) :: boolean()

Checks if data has expired.

Examples

iex> is_expired?(%Data{expires_in: 7200, inserted_at: ~N[2017-04-04 19:21:22.292762], ...}}
false

iex> is_expired?(%Data{expires_in: 10, inserted_at: ~N[2017-04-04 19:21:22.292762], ...}}
true

iex> is_expired?(%Data{expires_in: nil}}
false
Link to this function is_revoked?(arg1) View Source
is_revoked?(Ecto.Schema.t()) :: boolean()

Checks if data has been revoked.

Examples

iex> is_revoked?(%Data{revoked_at: nil, ...}}
false

iex> is_revoked?(%Data{revoked_at: ~N[2017-04-04 19:21:22.292762], ...}}
true
Link to this function parse_default_scope_string(server_scopes) View Source
parse_default_scope_string(binary() | nil) :: binary()
Link to this function put_scopes(changeset, default_server_scopes) View Source

Same as revoke/1 but raises error.

Revoke data.

Examples

iex> revoke(data)
{:ok, %Data{revoked_at: ~N[2017-04-04 19:21:22.292762], ...}}

iex> revoke(invalid_data)
{:error, %Ecto.Changeset{}}
Link to this function revoke_previous_refresh_token(access_token) View Source
revoke_previous_refresh_token(
  ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()
) ::
  {:ok, ExOauth2Provider.OauthAccessTokens.OauthAccessToken.t()}
  | {:error, Ecto.Changeset.t()}

Revokes token with refresh_token equal to previous_refresh_token and clears :previous_refresh_token attribute.

Examples

iex> revoke_previous_refresh_token(data)
{:ok, %OauthAccessToken{}}

iex> revoke_previous_refresh_token(invalid_data)
{:error, %Ecto.Changeset{}}
Link to this function validate_scopes(changeset) View Source
validate_scopes(Ecto.Changeset.t()) :: Ecto.Changeset.t()
Link to this function validate_scopes(changeset, server_scopes) View Source