Packages
boruta
2.2.2
3.0.0-beta.4
3.0.0-beta.3
3.0.0-beta.2
3.0.0-beta.1
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.2
2.2.1
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.2.1
0.2.0
0.1.1
0.1.0
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
Core of an OAuth/OpenID Connect provider enabling authorization in your applications.
Current section
Files
Jump to
Current section
Files
lib/boruta/oauth/revoke.ex
defmodule Boruta.Oauth.Revoke do
@moduledoc """
Access token revocation
"""
alias Boruta.Oauth.Authorization
alias Boruta.Oauth.RevokeRequest
@doc """
Revokes token according to the given `Boruta.Oauth.RevokeRequest`
## Examples
iex> token(%RevokeRequest{
client_id: "client_id",
client_secret: "client_secret",
token: "token"
})
:ok
"""
@spec token(
request :: %RevokeRequest{
client_id: String.t(),
client_secret: String.t(),
token: String.t()
}
) ::
:ok
| {:error, error :: Boruta.Oauth.Error.t()}
| {:error, error :: String.t()}
def token(%RevokeRequest{
client_id: client_id,
client_secret: client_secret,
token: value,
token_type_hint: token_type_hint
}) do
with {:ok, _client} <-
Authorization.Client.authorize(
id: client_id,
secret: client_secret,
grant_type: "revoke"
) do
token =
case token_type_hint do
"refresh_token" ->
with nil <- Boruta.AccessTokensAdapter.get_by(refresh_token: value) do
Boruta.AccessTokensAdapter.get_by(value: value)
end
_ ->
with nil <- Boruta.AccessTokensAdapter.get_by(value: value) do
Boruta.AccessTokensAdapter.get_by(refresh_token: value)
end
end
if token do
with {:ok, _token} <- Boruta.AccessTokensAdapter.revoke(token) do
:ok
end
else
# return :ok even for unexisting tokens
:ok
end
end
end
end