View Source ExUid2.Dsp (ex_uid2 v0.2.0)

This is the client module for DSP-side decryption of UID2 tokens.

By default, when the ExUid2 application starts, the ExUid2.Dsp server is started with the :active mode, which refreshes the keyring every hour.

To manually control the keyring refresh calls, set the application with the runtime: false option and start the ExUid2.Dsp server with ExUid2.Dsp.start_link(mode: :passive). Then, calling ExUid2.Dsp.refresh/0 will make the query and refresh the keyring.

Summary

Functions

Returns a specification to start this module under a supervisor.

Attempts to decrypt a base64 encoded UID2 token.

Triggers a query to the Uid2 opperator server to get the latest keyring. Not required when the Dsp server is started in :active mode (which is the default) or when ExUid2.Dsp.start_refresh_loop/0 has been called.

Starts hourly refreshing of the Keyring.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

decrypt_token(token, now_ms \\ :os.system_time(:millisecond))

View Source
@spec decrypt_token(binary(), non_neg_integer()) ::
  {:ok, ExUid2.Uid2.t()} | {:error, ExUid2.Encryption.encryption_error()}

Attempts to decrypt a base64 encoded UID2 token.

Example

iex> ExUid2.Dsp.decrypt("A3AAAAABI2RPtp1P7Fa66cRLOHzi2gkK2kxIEWpwX+cWgsLITmLS+/q7kHCuHMPhtweLapy0p8IXaR6T4eGlF3iloOSwzPaJ+PMUiRwdLVb8perCP4AmlnPeAlndOGAJNTlaSvqb1tUdUJwpOzkQv6yjE9LoLUT/82QhKt92WIehEdSjJm/YpSgLdMWazqXPzyJjTZ+GIgJn2k6qHb33AGoe5YSrrkp91xWL2H6Ziw==")
{:ok,
  %ExUid2.Uid2{
    uid: "ywsvDNINiZOVSsfkHpLpSJzXzhr6Jx9Z/4Q0+lsEUvM=",
    established_ms: 0,
    site_id: 2,
    site_key: %ExUid2.Keyring.Key{
      activates_ms: 0,
      created_ms: 0,
      expires_ms: 1722448017227,
      id: 2,
      secret: <<32, 251, 7, 194, 132, 154, 250, 86, 202, 116, 104, 29, 131, 192,
        139, 215, 48, 164, 11, 65, 226, 110, 167, 14, 108, 51, 254, 125, 65, 24,
        23, 133>>,
      keyset_id: nil
    },
    identity_scope: "UID2",
    version: 3,
    expires_ms: 1722448110794,
    identity_type: :email
  }}
@spec refresh() :: :ok | {:error, any()}

Triggers a query to the Uid2 opperator server to get the latest keyring. Not required when the Dsp server is started in :active mode (which is the default) or when ExUid2.Dsp.start_refresh_loop/0 has been called.

Starts hourly refreshing of the Keyring.

When the ExUid2.Dsp server is started with mode: :passive, it won't periodically query the Uid2 operator server to refresh the keyring. Calling ExUid2.Dsp.start_refresh_loop/0 will refresh the keyring and make the ExUid2.Dsp server refresh it again every hour.