ExOauth2Provider v0.2.1 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 active 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 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

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

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{}}

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

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_active_tokens_for(map) View Source

Gets all active tokens for resource owner.

Examples

iex> get_active_tokens_for(resource_owner)
[%OauthAccessToken{}, ...]
Link to this function get_by_previous_refresh_token_for(oauth_access_token) View Source

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

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

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

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(map, oauth_application, scopes) View Source

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

Examples

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

iex> get_matching_token_for(user, application, "read invalid")
nil
Link to this function get_or_create_token(owner, attrs \\ %{}) View Source

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

Examples

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

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

iex> get_or_create_token(user attrs)
{:error, %Ecto.Changeset{}}

Checks if an access token can be accessed.

Examples

iex> is_accessible?(token)
true

iex> is_accessible?(inaccessible_token)
false

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

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 put_scopes(changeset, server_scopes) View Source

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

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
Link to this function validate_scopes(changeset, server_scopes) View Source