validateToken method

Stream<Exception> validateToken({
  1. bool validateClaims = true,
  2. bool validateExpiry = true,
})

Implementation

Stream<Exception> validateToken(
    {bool validateClaims = true, bool validateExpiry = true}) async* {
  var keyStore = JsonWebKeyStore();
  var jwksUri = client.issuer.metadata.jwksUri;
  if (jwksUri != null) {
    keyStore.addKeySetUrl(jwksUri);
  }
  if (!await idToken.verify(keyStore,
      allowedArguments:
          client.issuer.metadata.idTokenSigningAlgValuesSupported)) {
    yield JoseException('Could not verify token signature');
  }

  yield* Stream.fromIterable(idToken.claims
      .validate(
          expiryTolerance: const Duration(seconds: 30),
          issuer: client.issuer.metadata.issuer,
          clientId: client.clientId,
          nonce: nonce)
      .where((e) =>
          validateExpiry ||
          !(e is JoseException && e.message.startsWith('JWT expired.'))));
}