ExFirebaseAuth.Mock (ex_firebase_auth v0.5.1)
This module will generate a public-private keypair and store it in ExFirebaseAuth's ETS tables. You can create ID tokens identical to Firebase's tokens for use in integrating testing your auth stack.
When enabled, tokens generated from this mock will be accepted by ExFirebaseAuth.Token.verify_token/1
Enabling the mock
In order to prevent non-google tokens from being added to real-world environments, you need to enable the mock in your app's configuration.
config :ex_firebase_auth, :mock,
enabled: true # defaults to false
Link to this section Summary
Functions
Generates and stores a new key pair in ETS tables. Note: this already gets called on app init, you probably do not need this.
Generates a firebase-like ID token with the mock's private key. Will raise when mock is not enabled.
Returns whether mocking is enabled, returns false by default
Link to this section Functions
generate_and_store_key_pair()
Specs
generate_and_store_key_pair() :: any()
Generates and stores a new key pair in ETS tables. Note: this already gets called on app init, you probably do not need this.
generate_token(sub, claims \\ %{})
Specs
Generates a firebase-like ID token with the mock's private key. Will raise when mock is not enabled.
Examples
iex> ExFirebaseAuth.Mock.generate_token("userid", %{"claim" => "value"})
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlLCJpc3MiOiJqb2UifQ.shLcxOl_HBBsOTvPnskfIlxHUibPN7Y9T4LhPB-iBwM"
is_enabled?()
Specs
is_enabled?() :: boolean()
Returns whether mocking is enabled, returns false by default