View Source ExOauth2Provider.AccessTokens (ExOauth2Provider v0.5.7)
Ecto schema for oauth access tokens
Summary
Functions
Creates an application access token.
Creates an access token.
Gets the most recent, acccessible, matching access token for an application.
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.
Checks if an access token can be accessed.
See ExOauth2Provider.Mixin.Expirable.is_expired?/1
.
See ExOauth2Provider.Mixin.Revocable.is_revoked?/1
.
See ExOauth2Provider.Mixin.Revocable.revoke/2
.
See ExOauth2Provider.Mixin.Revocable.revoke!/2
.
Revokes token with refresh_token
equal to
previous_refresh_token
and clears :previous_refresh_token
attribute.
Functions
@spec create_application_token(Ecto.Schema.t() | nil, map(), keyword()) :: {:ok, ExOauth2Provider.AccessTokens.AccessToken.t()} | {:error, Ecto.Changeset.t()}
Creates an application access token.
Examples
iex> create_application_token(application, %{scopes: "read write"}, otp_app: :my_app)
{:ok, %OauthAccessToken{}}
@spec create_token(Ecto.Schema.t(), map(), keyword()) :: {:ok, ExOauth2Provider.AccessTokens.AccessToken.t()} | {:error, Ecto.Changeset.t()}
Creates an access token.
Examples
iex> create_token(resource_owner, %{application: application, scopes: "read write"}, otp_app: :my_app)
{:ok, %OauthAccessToken{}}
iex> create_token(resource_owner, %{scopes: "read write"}, otp_app: :my_app)
{:ok, %OauthAccessToken{}}
iex> create_token(resource_owner, %{expires_in: "invalid"}, otp_app: :my_app)
{:error, %Ecto.Changeset{}}
@spec get_application_token_for( ExOauth2Provider.Applications.Application.t(), binary(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets the most recent, acccessible, matching access token for an application.
Examples
iex> get_application_token_for(application, "read write", otp_app: :my_app)
%OauthAccessToken{}
iex> get_application_token_for(application, "read invalid", otp_app: :my_app)
nil
@spec get_authorized_tokens_for( Ecto.Schema.t(), keyword() ) :: [ExOauth2Provider.AccessTokens.AccessToken.t()]
Gets all authorized access tokens for resource owner.
Examples
iex> get_authorized_tokens_for(resource_owner, otp_app: :my_app)
[%OauthAccessToken{}, ...]
@spec get_by_previous_refresh_token_for( ExOauth2Provider.AccessTokens.AccessToken.t(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets an old access token by previous refresh token.
Examples
iex> get_by_previous_refresh_token_for(new_access_token, otp_app: :my_app)
%OauthAccessToken{}
iex> get_by_previous_refresh_token_for(new_access_token, otp_app: :my_app)
nil
@spec get_by_refresh_token( binary(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets an access token by the refresh token.
Examples
iex> get_by_refresh_token("c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d", otp_app: :my_app)
%OauthAccessToken{}
iex> get_by_refresh_token("75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc", otp_app: :my_app)
nil
get_by_refresh_token_for(application, refresh_token, config \\ [])
View Source@spec get_by_refresh_token_for( ExOauth2Provider.Applications.Application.t(), binary(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets an access token by the refresh token belonging to an application.
Examples
iex> get_by_refresh_token_for(application, "c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d", otp_app: :my_app)
%OauthAccessToken{}
iex> get_by_refresh_token_for(application, "75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc", otp_app: :my_app)
nil
@spec get_by_token( binary(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets a single access token.
Examples
iex> get_by_token("c341a5c7b331ef076eb4954668d54f590e0009e06b81b100191aa22c93044f3d", otp_app: :my_app)
%OauthAccessToken{}
iex> get_by_token("75d72f326a69444a9287ea264617058dbbfe754d7071b8eef8294cbf4e7e0fdc", otp_app: :my_app)
nil
@spec get_token_for( Ecto.Schema.t(), ExOauth2Provider.Applications.Application.t(), binary(), keyword() ) :: ExOauth2Provider.AccessTokens.AccessToken.t() | nil
Gets the most recent, acccessible, matching access token for a resource owner.
Examples
iex> get_token_for(resource_owner, application, "read write", otp_app: :my_app)
%OauthAccessToken{}
iex> get_token_for(resource_owner, application, "read invalid", otp_app: :my_app)
nil
@spec is_accessible?(ExOauth2Provider.AccessTokens.AccessToken.t() | nil) :: boolean()
Checks if an access token can be accessed.
Examples
iex> is_accessible?(token)
true
iex> is_accessible?(inaccessible_token)
false
See ExOauth2Provider.Mixin.Expirable.is_expired?/1
.
See ExOauth2Provider.Mixin.Revocable.is_revoked?/1
.
See ExOauth2Provider.Mixin.Revocable.revoke/2
.
See ExOauth2Provider.Mixin.Revocable.revoke!/2
.
Revokes token with refresh_token
equal to
previous_refresh_token
and clears :previous_refresh_token
attribute.
Examples
iex> revoke_previous_refresh_token(data, otp_app: :my_app)
{:ok, %OauthAccessToken{}}
iex> revoke_previous_refresh_token(invalid_data, otp_app: :my_app)
{:error, %Ecto.Changeset{}}