createAuthMessage static method

String createAuthMessage(
  1. String authId,
  2. String helloNonce,
  3. HashMap authExtra,
  4. Extra challengeExtra,
)

This creates the SCRAM authmessage according to the WAMP-SCRAM specs

Implementation

static String createAuthMessage(String authId, String helloNonce,
    HashMap authExtra, Extra challengeExtra) {
  var clientFirstBare = 'n=${Saslprep.saslprep(authId)},r=$helloNonce';
  var serverFirst =
      'r=${challengeExtra.nonce!},s=${challengeExtra.salt!},i=${challengeExtra.iterations}';
  String? cBindName = authExtra['channel_binding'];
  String? cBindData = authExtra['cbind_data'];
  var cBindFlag = cBindName == null ? 'n' : 'p=$cBindName';
  var cBindInput =
      '$cBindFlag,,${cBindData == null ? '' : base64.decode(cBindData) as String}';
  var clientFinalNoProof =
      'c=${base64.encode(cBindInput.codeUnits)},r=${authExtra['nonce']}';
  return '$clientFirstBare,$serverFirst,$clientFinalNoProof';
}