Introspect Authentication Token
Turn Pass Balances on with transaction_notification_url and balance_tile_identifiers on the card template. Both are set on a pass when it is provisioned, so changing them later only affects passes provisioned after the change; passes already in Wallet keep the URL and tiles they were provisioned with.
Your Balances Web Service calls this to check the authenticationToken Wallet sent it before returning any balances. Tokens stop working when the pass is deleted or unlinked, when the device is removed or suspended, or when the device registers again, so don't cache a result for long, and never log the token.
Requires the can_read_passes permission.
authenticationToken
string
wallet_pass_id
string
Request
# Build the JSON payload from what Wallet sent your Balances Web Service
PAYLOAD='{"authenticationToken":"'"$AUTHENTICATION_TOKEN"'","wallet_pass_id":"0xd3v1c3-1a2b3c4d"}'
# Sign the payload
PAYLOAD_B64=$(printf '%s' "$PAYLOAD" | openssl base64 -A)
SIG=$(printf '%s' "$PAYLOAD_B64" | openssl dgst -sha256 -hmac "$SECRET_KEY" -hex | awk '{print $NF}')
curl -X POST \
-H "X-ACCT-ID: $ACCOUNT_ID" \
-H "X-PAYLOAD-SIG: $SIG" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"https://api.accessgrid.com/cns/v1/introspect"
require 'accessgrid'
account_id = ENV['ACCOUNT_ID']
secret_key = ENV['SECRET_KEY']
client = AccessGrid::Client.new(account_id, secret_key)
# authentication_token and wallet_pass_id come from Wallet's request
# to your Balances Web Service
result = client.pass_balances.introspect(
authentication_token: authentication_token,
wallet_pass_id: "0xd3v1c3-1a2b3c4d"
)
if result.active
puts "Valid for pass #{result.internal_id}"
else
puts "Rejected"
end
import AccessGrid from 'accessgrid';
const accountId = process.env.ACCOUNT_ID;
const secretKey = process.env.SECRET_KEY;
const client = new AccessGrid(accountId, secretKey);
// authenticationToken and walletPassId come from Wallet's request
// to your Balances Web Service
const introspect = async (authenticationToken) => {
try {
const result = await client.passBalances.introspect({
authenticationToken,
walletPassId: '0xd3v1c3-1a2b3c4d'
});
if (result.active) {
console.log(`Valid for pass ${result.internalId}`);
} else {
console.log('Rejected');
}
} catch (error) {
console.error('Error introspecting token:', error);
}
};
introspect(authenticationToken);
from accessgrid import AccessGrid
import os
account_id = os.getenv('ACCOUNT_ID')
secret_key = os.getenv('SECRET_KEY')
client = AccessGrid(account_id, secret_key)
# authentication_token and wallet_pass_id come from Wallet's request
# to your Balances Web Service
result = client.pass_balances.introspect(
authentication_token=authentication_token,
wallet_pass_id="0xd3v1c3-1a2b3c4d"
)
if result.active:
print(f"Valid for pass {result.internal_id}")
else:
print("Rejected")
package main
import (
"context"
"fmt"
"os"
"github.com/Access-Grid/accessgrid-go"
)
func main() {
accountID := os.Getenv("ACCOUNT_ID")
secretKey := os.Getenv("SECRET_KEY")
client, err := accessgrid.NewClient(accountID, secretKey)
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}
// AuthenticationToken and WalletPassID come from Wallet's request
// to your Balances Web Service
params := accessgrid.IntrospectParams{
AuthenticationToken: authenticationToken,
WalletPassID: "0xd3v1c3-1a2b3c4d",
}
ctx := context.Background()
result, err := client.PassBalances.Introspect(ctx, params)
if err != nil {
fmt.Printf("Error introspecting token: %v\n", err)
return
}
if result.Active {
fmt.Printf("Valid for pass %s\n", result.InternalID)
} else {
fmt.Println("Rejected")
}
}
using AccessGrid;
using System;
using System.Threading.Tasks;
public async Task IntrospectAsync(string authenticationToken)
{
var accountId = Environment.GetEnvironmentVariable("ACCOUNT_ID");
var secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");
var client = new AccessGridClient(accountId, secretKey);
// authenticationToken and WalletPassID come from Wallet's request
// to your Balances Web Service
var result = await client.PassBalances.IntrospectAsync(new IntrospectRequest
{
AuthenticationToken = authenticationToken,
WalletPassID = "0xd3v1c3-1a2b3c4d"
});
if (result.Active)
{
Console.WriteLine($"Valid for pass {result.InternalID}");
}
else
{
Console.WriteLine("Rejected");
}
}
import com.organization.accessgrid.AccessGridClient;
import com.organization.accessgrid.model.IntrospectRequest;
import com.organization.accessgrid.model.IntrospectResult;
public class PassBalancesService {
private final AccessGridClient client;
public PassBalancesService() {
String accountId = System.getenv("ACCOUNT_ID");
String secretKey = System.getenv("SECRET_KEY");
this.client = new AccessGridClient(accountId, secretKey);
}
// authenticationToken and walletPassId come from Wallet's request
// to your Balances Web Service
public void introspect(String authenticationToken) throws AccessGridException {
IntrospectRequest request = IntrospectRequest.builder()
.authenticationToken(authenticationToken)
.walletPassId("0xd3v1c3-1a2b3c4d")
.build();
IntrospectResult result = client.passBalances().introspect(request);
if (result.isActive()) {
System.out.printf("Valid for pass %s%n", result.getInternalId());
} else {
System.out.println("Rejected");
}
}
}
<?php
require 'vendor/autoload.php';
use AccessGrid\AccessGridClient;
$accountId = $_ENV['ACCOUNT_ID'];
$secretKey = $_ENV['SECRET_KEY'];
$client = new AccessGridClient($accountId, $secretKey);
// $authenticationToken and wallet_pass_id come from Wallet's request
// to your Balances Web Service
$result = $client->passBalances->introspect([
'authentication_token' => $authenticationToken,
'wallet_pass_id' => '0xd3v1c3-1a2b3c4d'
]);
if ($result->active) {
echo "Valid for pass {$result->internal_id}\n";
} else {
echo "Rejected\n";
}
{:ok, client} = AccessGrid.new(
System.get_env("ACCOUNT_ID"),
System.get_env("SECRET_KEY")
)
# authentication_token and wallet_pass_id come from Wallet's request
# to your Balances Web Service
case AccessGrid.PassBalances.introspect(client,
authentication_token: authentication_token,
wallet_pass_id: "0xd3v1c3-1a2b3c4d"
) do
{:ok, %{active: true} = result} -> IO.puts("Valid for pass #{result.internal_id}")
_ -> IO.puts("Rejected")
end
Response
// 200 OK - token is valid for this wallet_pass_id
{
"active": true,
"device_id": "0xd3v1c3-1a2b3c4d",
"internal_id": "0x1nt3rn4l"
}
// 401 Unauthorized - unknown, rotated or revoked token, or a wallet_pass_id
// that doesn't belong to it
{
"active": false
}