Skip to content

AuthenticationData model cannot send required fields for UIA stages (e.g. m.login.recaptcha response) #2287

Description

@2001arman

Preflight Checklist

  • I could not find a solution in the existing issues, docs, nor discussions

Describe your problem

Problem

The AuthenticationData model currently only supports the following fields:

class AuthenticationData {
  String? type;
  String? session;
}

However, according to the Matrix Client-Server API specification, UIA authentication stages may require additional parameters depending on the stage.

For example, the m.login.recaptcha stage requires the response field containing the captcha token.

Spec reference:
https://spec.matrix.org/v1.17/client-server-api/#google-recaptcha

Example request from the spec:

{
  "auth": {
    "type": "m.login.recaptcha",
    "session": "SESSION_ID",
    "response": "CAPTCHA_TOKEN"
  }
}

Because AuthenticationData does not allow extra fields, it is currently impossible to send the required response value using the SDK.

This results in Synapse returning:
M_CAPTCHA_NEEDED: Captcha response is required

Describe your ideal solution

Proposed Solution

Allow arbitrary authentication parameters to be passed through the AuthenticationData model.

Example implementation:

class AuthenticationData {
  String? type;
  String? session;
  Map<String, Object?>? additionalFields;

  AuthenticationData({
    this.type,
    this.session,
    this.additionalFields,
  });

  Map<String, Object?> toJson() {
    final data = <String, Object?>{};
    if (type != null) data['type'] = type;
    if (session != null) data['session'] = session;
    if (additionalFields != null) data.addAll(additionalFields!);
    return data;
  }
}

Example Usage

auth: AuthenticationData(
  type: AuthenticationTypes.recaptcha,
  session: session,
  additionalFields: {
    "response": captchaToken,
  },
)

Why This Is Needed

Matrix UIA (User-Interactive Authentication) supports many authentication stages, each requiring different fields such as:

  • response for m.login.recaptcha
  • threepid_creds for m.login.email.identity
  • identifier / password for m.login.password

Restricting the model to only type and session prevents the SDK from supporting the full UIA specification.

Environment

  • matrix-dart-sdk version: (your version)
  • homeserver: Synapse

Version

6.1.1

Security requirements

No response

Additional Context

Register using captcha

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions