* fix(cognito): fire PreTokenGeneration for client_credentials tokens
The token endpoint issued client_credentials access tokens without ever
invoking the pool's pre token generation trigger, so claims and scopes a
V3_0 function returned never reached M2M tokens.
As on AWS, the trigger now fires with triggerSource
TokenGeneration_ClientCredentials when PreTokenGenerationConfig's
LambdaVersion is V3_0, and is skipped for V1_0 and V2_0. The event
matches the one AWS documents for the token endpoint: userName
ClientCredentials, the granted scopes, empty userAttributes, a null
groupConfiguration, the request's aws_client_metadata, and a response
whose claimsAndScopeOverrideDetails is null. Only accessTokenGeneration
applies to the token; claims that identify the client (sub, client_id,
token_use, version, iss, exp, iat, jti and the cognito: namespace)
cannot be changed, and an added aud must equal the client ID.
Fixes#7792
* fix(cognito): protect username and scope in client-credentials tokens
Addresses review feedback on the client-credentials pre token generation
trigger.
A V3_0 trigger could add a username claim to a machine access token, and
could replace or suppress the granted scope through claimsToAddOrOverride
and claimsToSuppress. As on AWS, username (along with device_key and
at_hash) is now protected in machine tokens, and scope changes only
through scopesToAdd and scopesToSuppress.
aws_client_metadata with a null value is now refused with
invalid_request, like any other value that is not a string.
* fix(cognito): send version 3 and accept only string metadata for client credentials
The client-credentials pre token generation event now carries version "3",
as in the AWS token endpoint example. aws_client_metadata is read as a JSON
tree and refused unless it is an object whose values are all JSON strings,
so numbers and booleans are no longer coerced to strings.