Skip to main content

Verify With Token

Use the verifyWithToken() method when you already have a verification token and simply want to launch the verification session with it. This is useful when tokens are generated ahead of time (for example, server-side via the token generation API) and handed to the client to complete the verification.

1. Creating a Metric instance​

The Metric() constructor is used to create a Metric instance

const metric = new window.Metric({
client_id: "your_public_key",
client_secret: "your_secret_key",
});

Parameters​

client_id: An API encrypted public key string. For example, AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe


client_secret: An API encrypted secret key string. For example, AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe


2. Triggering a verification procedure​

The verifyWithToken() method on the Metric object is called with two arguments: token and callback. This creates an iframe element that loads the verification process for the supplied token. Once the verification process is complete, the iframe is removed from the DOM and the callback function is called with the results of the verification process.

const metric = new window.Metric({
client_id: "your_public_key",
client_secret: "your_secret_key",
});

metric.verifyWithToken(token, callback);

Parameters​

token: A string representing a previously generated verification token. See Generating Tokens for how to create one.


callback: A function that takes a single argument results. The function will be called when the verification is complete, and results will contain a status property describing the outcome of the verification.

Full Example​

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Page Title</title>
</head>
<body>
<button onclick="verifyUser()">Verify Me</button>

<script type="text/javascript" src="https://sdk.dev.metric.africa/v1"></script>

<script>
const verifyUser = () => {
const metric = new window.Metric({
client_id: "XXXXXXXXXX",
client_secret: "XXXXXXXXXX",
});

metric.verifyWithToken("your_verification_token", (results) => {
console.log(results.status);
});
};
</script>
</body>
</html>