deviceRequestHash function
The recommended request hash of a device check:
base64url(SHA-256("limenia:" + externalUserId + ":" + nonce)), without
= padding (43 characters), as the spec of the device connector
recommends.
The backend of the app picks nonce at random for every check (e.g. with
newDeviceNonce), computes the hash for the user it authenticated and
gives it to the app. The app requests the token with it (the requestHash
of a Play Integrity standard request) and sends the token back. The
backend forwards the token with the same hash in
DeviceCheckRequest.requestHash, and Limenia checks that the token was
requested with it. That binds the token to the user and to this one
check, so a token of another device cannot be passed off. Play Integrity
accepts a request hash of up to 500 characters.
iOS has no such binding: DeviceCheck ignores the hash, and a token is bound only by being single-use.
Implementation
String deviceRequestHash(String externalUserId, String nonce) =>
base64Url.encode(sha256(utf8.encode('limenia:$externalUserId:$nonce'))).replaceAll('=', '');