jwtDecode function

Map<String, dynamic> jwtDecode(
  1. String jwt, {
  2. required String algorithm,
  3. required Key key,
})

Implementation

Map<String, dynamic> jwtDecode(String jwt, {required String algorithm, required Key key}) {
  Map<String, dynamic>? decoded;

  if (algorithm == 'EdDSA') {
    if (!(key is OkpKey)) {
      throw FormatException("EdDSA algorithm must use OKP key");
    }

    if (key.crv != 'Ed448') {
      throw UnsupportedError(
        "jwtDecode using the EdDSA algorithm currently only supports Ed448"
      );
    }

    decoded = _ed448JwtDecode(jwt, key);
  }

  if (decoded == null) {
    throw UnsupportedError("jwtDecode currently only supports EdDSA algorithm");
  }

  _validateClaims(decoded);

  return decoded;
}