negotiate method
- XMLNode nonza
override
Called with the currently received nonza nonza
when the negotiator is active.
If the negotiator is just elected to be the next one, then nonza
is equal to
the <stream:features /> nonza.
Returns the next state of the negotiator. If done or retryLater is selected, then negotiator won't be called again. If retryLater is returned, then the negotiator must switch some internal state to prevent getting matched immediately again. If ready is returned, then the negotiator indicates that it is not done with negotiation.
Implementation
@override
Future<Result<NegotiatorState, NegotiatorError>> negotiate(
XMLNode nonza,
) async {
if (!_authSent) {
final data = await getRawStep('');
attributes.sendNonza(
SaslPlainAuthNonza(data),
);
_authSent = true;
return const Result(NegotiatorState.ready);
} else {
final tag = nonza.tag;
if (tag == 'success') {
attributes.setAuthenticated();
return const Result(NegotiatorState.done);
} else {
// We assume it's a <failure/>
final error = nonza.children.first.tag;
await attributes.sendEvent(AuthenticationFailedEvent(error));
return Result(
SaslError.fromFailure(nonza),
);
}
}
}