UID2::Client - Unified ID 2.0 Perl Client
use UID2::Client;
my $client = UID2::Client->new({
endpoint => 'https://prod.uidapi.com',
auth_key => 'your_auth_key',
secret_key => 'your_secret_key',
});
my $result = $client->refresh;
die $result->{reason} unless $result->{is_success};
my $decrypted = $client->decrypt($uid2_token);
if ($decrypted->{is_success}) {
say $result->{uid};
}
This module provides an interface to Unified ID 2.0 API.
my $client = UID2::Client->new(\%options);
Creates and returns a new UID2 client with a hashref of options.
Valid options are:
-
endpoint
The UID2 Endpoint (required).
-
auth_key
A bearer token in the request's authorization header (required).
-
secret_key
A secret key for encrypting/decrypting the request/response body (required).
-
identity_scope
UID2 or EUID. Defaults to UID2.
-
http_options
Options to pass to the HTTP::Tiny constructor.
-
http
The HTTP::Tiny instance.
Only one of http_options or http can be specified.
my $client = UID2::Client->new_euid(\%options);
Calls new() with EUID identity_scope.
my $result = $client->refresh();
Fetch the latest keys and returns a hashref containing the response. The hashref will have the following keys:
-
is_success
Boolean indicating whether the operation succeeded.
-
reason
Returns reason for failure if is_success is false.
$client->refresh_json($json);
Updates keys with the JSON string and returns a hashref containing the response. The hashref will have same keys of refresh().
my $json = $client->get_latest_keys();
Gets latest keys from UID2 API and returns the JSON string.
Dies on errors, e.g. HTTP errors.
my $result = $client->decrypt($uid2_token);
# or
my $result = $client->decrypt($uid2_token, $timestamp);
Decrypts an advertising token and returns a hashref containing the response. The hashref will have the following keys:
-
is_success
Boolean indicating whether the operation succeeded.
-
status
Returns failed status if is_success is false.
See UID2::Client::DecryptionStatus for more details.
-
uid
The UID2 string.
-
site_id
-
site_key_site_id
-
established
my $result = $client->encrypt_data($data, \%request);
Encrypts arbitrary data with a hashref of requests.
Valid options are:
-
advertising_token
Specify the UID2 Token.
-
site_id
-
initialization_vector
-
now
-
key
One of advertising_token or site_id must be passed.
Returns a hashref containing the response. The hashref will have the following keys:
-
is_success
Boolean indicating whether the operation succeeded.
-
status
Returns failed status if is_success is false.
See UID2::Client::EncryptionStatus for more details.
-
encrypted_data
my $result = $client->decrypt_data($encrypted_data);
Decrypts data encrypted with encrypt_data(). Returns a hashref containing the response. The hashref will have the following keys:
- is_success
- status
- decrypted_data
- encrypted_at
https://github.com/UnifiedID2/uid2docs
Copyright (C) Jiro Nishiguchi.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Jiro Nishiguchi jiro@cpan.org