cassette v1.5.0 Cassette
Library to generate and validate CAS TGTs/STs
Client usage
Generate a tgt and a st for some service:
iex> Cassette.tgt
{:ok, "TGT-example-abcd"}
iex> Cassette.st("http://some.authenticated/url")
{:ok, "ST-example-1234"}
Validation usage:
iex> st = FakeCas.valid_st
iex> Cassette.validate(st, "http://some.authenticated/url")
{:ok, Cassette.User.new("example", "customer", ["ACME_ADMIN"],
%{"cn" => "John Smith"})}
Customization and multiple configurations
If you need multiple Cassette servers please refer to Cassette.Support
for
macros that allow to build your own services.
Running on development without an actual CAS server
The FakeCas
module we use for testing is available on :dev
as well.
To set it up and configure the default Cassette
, add to yor dependencies on
mix.exs
:
{:fake_cas, "~> 1.0"}
Then initialize it with:
iex> FakeCas.Support.initialize
:ok
With the configuration set, Cassette
will always return the TGT returned by
FakeCas.valid_tgt/0
:
iex> tgt = FakeCas.valid_tgt
iex> {:ok, ^tgt} = Cassette.tgt
{:ok, "TGT-example-abcd"}
Using the stored valid TGT, Casette
will always generate the same ST:
iex> st = FakeCas.valid_st
iex> {:ok, ^st} = Cassette.st("some-service")
{:ok, "ST-example-1234"}
Trying to validate the ST in FakeCas.valid_st/0
will always succeed for any
service:
iex> st = FakeCas.valid_st
iex> {:ok, _} = Cassette.validate(st, "some-service")
{:ok, Cassette.User.new("example", "customer", ["ACME_ADMIN"],
%{"cn" => "John Smith"})}
And trying to validate any other ST will always fail:
iex> Cassette.validate("any-other-st", "some-service")
{:error, "INVALID_SERVICE: ticket 'X' is invalid"}
Link to this section Summary
Functions
Generates a child spec for a custom Cassette module for Elixir < 1.5
Elixir 1.5+ compatible child spec
Returns the configuration used by this Cassette server
Generates a Service Ticket for the given service
Generates a Ticket Granting Ticket
Validates a given ticket
against the given service
or the service set
in the configuration
Link to this section Functions
Generates a child spec for a custom Cassette module for Elixir < 1.5
If you are adding a custom cassette instance, you can add to your supervision tree by using:
defmodule MyCas do
use Cassette.Support, process_name: :MyCas
end
children = [
# ...
MyCas.child_spec
]
Supervisor.start_link(children, ...)
Elixir 1.5+ compatible child spec.
If you are adding a custom cassette instance, you can add to your supervision tree by using:
defmodule MyCas do
use Cassette.Support, process_name: :MyCas
end
children = [
# ...
MyCas
]
Supervisor.start_link(children, ...)
Returns the configuration used by this Cassette server
Will return the default configuration if not provided.
Please refer to Cassette.Config.t
for details
Generates a Service Ticket for the given service
This function retries once when the TGT is expired on the server side.
Generates a Ticket Granting Ticket
validate(String.t(), String.t(), timeout()) :: {:ok, Cassette.User.t()} | {:error, term()}
Validates a given ticket
against the given service
or the service set
in the configuration