decodeCodeMieSsoToken function

Map<String, String> decodeCodeMieSsoToken(
  1. String raw
)

Decodes the callback token parameter: base64 JSON with a cookies object. Throws FormatException on any malformed shape.

Implementation

Map<String, String> decodeCodeMieSsoToken(String raw) {
  final Object? decoded;
  try {
    decoded = jsonDecode(utf8.decode(base64.decode(base64.normalize(raw))));
  } on Object {
    throw const FormatException('CodeMie SSO token is not base64 JSON');
  }
  if (decoded is! Map) {
    throw const FormatException('CodeMie SSO token is not an object');
  }
  final cookies = decoded['cookies'];
  if (cookies is! Map) {
    throw const FormatException('CodeMie SSO token has no cookies');
  }
  return {
    for (final entry in cookies.entries)
      if (entry.value is String) entry.key.toString(): entry.value as String,
  };
}