Packages
boruta
2.3.1
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/responses/introspect.ex
defmodule Boruta.Oauth.IntrospectResponse do
@moduledoc """
Response returned in case of introspection request success. Provides mandatory data needed to respond to token introspection.
"""
@type t :: %__MODULE__{
active: boolean(),
client_id: String.t(),
username: String.t(),
scope: String.t(),
sub: String.t(),
iss: String.t(),
exp: integer(),
iat: integer(),
private_key: String.t()
}
@enforce_keys [:active]
defstruct [
active: nil,
client_id: nil,
username: nil,
scope: nil,
sub: nil,
iss: "boruta",
exp: nil,
iat: nil,
private_key: nil
]
alias Boruta.Config
alias Boruta.Oauth.Client
alias Boruta.Oauth.IntrospectResponse
alias Boruta.Oauth.ResourceOwner
alias Boruta.Oauth.Token
@spec from_token(token :: Token.t()) :: introspect_response :: t()
def from_token(%Token{
client: %Client{id: id, private_key: private_key},
sub: sub,
resource_owner: resource_owner,
expires_at: expires_at,
scope: scope,
inserted_at: inserted_at
}) do
username = case resource_owner do
%ResourceOwner{username: username} -> username
nil -> nil
end
%IntrospectResponse{
active: true,
client_id: id,
username: username,
scope: scope,
sub: sub,
iss: Config.issuer(),
exp: expires_at,
iat: DateTime.to_unix(inserted_at),
private_key: private_key
}
end
@spec from_error(error :: Boruta.Oauth.Error.t()) :: introspect_response :: %IntrospectResponse{active: false}
def from_error(_), do: %IntrospectResponse{active: false}
end