You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Support msisdn registration and signin (#384)
* Functionality for msisdn signin * Add methods to request tokens from synapse to do msisdn verification * Extend interactive-auth to work with m.email.identity (which is significant since email auth is quite a chunk more complex). * Oops, fix merge * Fix lint * Add submitMsisdnToken * Support the bind_msisdn param to register Change the bind_email flag to an object with keys 'email' and 'msisdn', backwards compatibly.
This commit is contained in:
@@ -125,7 +125,9 @@ MatrixBaseApis.prototype.makeTxnId = function() {
|
||||
* @param {string} password
|
||||
* @param {string} sessionId
|
||||
* @param {Object} auth
|
||||
* @param {boolean} bindEmail
|
||||
* @param {Object} bindThreepids Set key 'email' to true to bind any email
|
||||
* threepid uses during registration in the ID server. Set 'msisdn' to
|
||||
* true to bind msisdn.
|
||||
* @param {string} guestAccessToken
|
||||
* @param {module:client.callback} callback Optional.
|
||||
* @return {module:client.Promise} Resolves: TODO
|
||||
@@ -133,9 +135,16 @@ MatrixBaseApis.prototype.makeTxnId = function() {
|
||||
*/
|
||||
MatrixBaseApis.prototype.register = function(
|
||||
username, password,
|
||||
sessionId, auth, bindEmail, guestAccessToken,
|
||||
sessionId, auth, bindThreepids, guestAccessToken,
|
||||
callback,
|
||||
) {
|
||||
// backwards compat
|
||||
if (bindThreepids === true) {
|
||||
bindThreepids = {email: true};
|
||||
} else if (bindThreepids === null || bindThreepids === undefined) {
|
||||
bindThreepids = {};
|
||||
}
|
||||
|
||||
if (auth === undefined || auth === null) {
|
||||
auth = {};
|
||||
}
|
||||
@@ -152,8 +161,11 @@ MatrixBaseApis.prototype.register = function(
|
||||
if (password !== undefined && password !== null) {
|
||||
params.password = password;
|
||||
}
|
||||
if (bindEmail !== undefined && bindEmail !== null) {
|
||||
params.bind_email = bindEmail;
|
||||
if (bindThreepids.email) {
|
||||
params.bind_email = true;
|
||||
}
|
||||
if (bindThreepids.msisdn) {
|
||||
params.bind_msisdn = true;
|
||||
}
|
||||
if (guestAccessToken !== undefined && guestAccessToken !== null) {
|
||||
params.guest_access_token = guestAccessToken;
|
||||
@@ -1143,6 +1155,35 @@ MatrixBaseApis.prototype.requestEmailToken = function(email, clientSecret,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Submits an MSISDN token to the identity server
|
||||
*
|
||||
* This is used when submitting the code sent by SMS to a phone number.
|
||||
* The ID server has an equivalent API for email but the js-sdk does
|
||||
* not expose this, since email is normally validated by the user clicking
|
||||
* a link rather than entering a code.
|
||||
*
|
||||
* @param {string} sid The sid given in the response to requestToken
|
||||
* @param {string} clientSecret A secret binary string generated by the client.
|
||||
* This must be the same value submitted in the requestToken call.
|
||||
* @param {string} token The token, as enetered by the user.
|
||||
*
|
||||
* @return {module:client.Promise} Resolves: Object, currently with no parameters.
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
* @throws Error if No ID server is set
|
||||
*/
|
||||
MatrixBaseApis.prototype.submitMsisdnToken = function(sid, clientSecret, token) {
|
||||
const params = {
|
||||
sid: sid,
|
||||
client_secret: clientSecret,
|
||||
token: token,
|
||||
};
|
||||
return this._http.idServerRequest(
|
||||
undefined, "POST", "/validate/msisdn/submitToken",
|
||||
params, httpApi.PREFIX_IDENTITY_V1,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks up the public Matrix ID mapping for a given 3rd party
|
||||
* identifier from the Identity Server
|
||||
|
||||
Reference in New Issue
Block a user