mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Merge branch 'develop' of github.com:matrix-org/synapse into release-v0.0.1
This commit is contained in:
commit
239622f80b
@ -233,56 +233,68 @@ class SynapseCmd(cmd.Cmd):
|
|||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
def do_3pidrequest(self, line):
|
def do_emailrequest(self, line):
|
||||||
"""Requests the association of a third party identifier
|
"""Requests the association of a third party identifier
|
||||||
<medium> The medium of the identifer (currently only 'email')
|
<address> The email address)
|
||||||
<address> The address of the identifer (ie. the email address)
|
<clientSecret> A string of characters generated when requesting an email that you'll supply in subsequent calls to identify yourself
|
||||||
|
<sendAttempt> The number of times the user has requested an email. Leave this the same between requests to retry the request at the transport level. Increment it to request that the email be sent again.
|
||||||
"""
|
"""
|
||||||
args = self._parse(line, ['medium', 'address'])
|
args = self._parse(line, ['address', 'clientSecret', 'sendAttempt'])
|
||||||
|
|
||||||
if not args['medium'] == 'email':
|
postArgs = {'email': args['address'], 'clientSecret': args['clientSecret'], 'sendAttempt': args['sendAttempt']}
|
||||||
print "Only email is supported currently"
|
|
||||||
return
|
|
||||||
|
|
||||||
postArgs = {'email': args['address'], 'clientSecret': '____'}
|
reactor.callFromThread(self._do_emailrequest, postArgs)
|
||||||
|
|
||||||
reactor.callFromThread(self._do_3pidrequest, postArgs)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _do_3pidrequest(self, args):
|
def _do_emailrequest(self, args):
|
||||||
url = self._identityServerUrl()+"/matrix/identity/api/v1/validate/email/requestToken"
|
url = self._identityServerUrl()+"/matrix/identity/api/v1/validate/email/requestToken"
|
||||||
|
|
||||||
json_res = yield self.http_client.do_request("POST", url, data=urllib.urlencode(args), jsonreq=False,
|
json_res = yield self.http_client.do_request("POST", url, data=urllib.urlencode(args), jsonreq=False,
|
||||||
headers={'Content-Type': ['application/x-www-form-urlencoded']})
|
headers={'Content-Type': ['application/x-www-form-urlencoded']})
|
||||||
print json_res
|
print json_res
|
||||||
if 'tokenId' in json_res:
|
if 'sid' in json_res:
|
||||||
print "Token ID %s sent" % (json_res['tokenId'])
|
print "Token sent. Your session ID is %s" % (json_res['sid'])
|
||||||
|
|
||||||
def do_3pidvalidate(self, line):
|
def do_emailvalidate(self, line):
|
||||||
"""Validate and associate a third party ID
|
"""Validate and associate a third party ID
|
||||||
<medium> The medium of the identifer (currently only 'email')
|
<sid> The session ID (sid) given to you in the response to requestToken
|
||||||
<tokenId> The identifier iof the token given in 3pidrequest
|
|
||||||
<token> The token sent to your third party identifier address
|
<token> The token sent to your third party identifier address
|
||||||
|
<clientSecret> The same clientSecret you supplied in requestToken
|
||||||
"""
|
"""
|
||||||
args = self._parse(line, ['medium', 'tokenId', 'token'])
|
args = self._parse(line, ['sid', 'token', 'clientSecret'])
|
||||||
|
|
||||||
if not args['medium'] == 'email':
|
postArgs = { 'sid' : args['sid'], 'token' : args['token'], 'clientSecret': args['clientSecret'] }
|
||||||
print "Only email is supported currently"
|
|
||||||
return
|
|
||||||
|
|
||||||
postArgs = { 'tokenId' : args['tokenId'], 'token' : args['token'] }
|
reactor.callFromThread(self._do_emailvalidate, postArgs)
|
||||||
postArgs['mxId'] = self.config["user"]
|
|
||||||
|
|
||||||
reactor.callFromThread(self._do_3pidvalidate, postArgs)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _do_3pidvalidate(self, args):
|
def _do_emailvalidate(self, args):
|
||||||
url = self._identityServerUrl()+"/matrix/identity/api/v1/validate/email/submitToken"
|
url = self._identityServerUrl()+"/matrix/identity/api/v1/validate/email/submitToken"
|
||||||
|
|
||||||
json_res = yield self.http_client.do_request("POST", url, data=urllib.urlencode(args), jsonreq=False,
|
json_res = yield self.http_client.do_request("POST", url, data=urllib.urlencode(args), jsonreq=False,
|
||||||
headers={'Content-Type': ['application/x-www-form-urlencoded']})
|
headers={'Content-Type': ['application/x-www-form-urlencoded']})
|
||||||
print json_res
|
print json_res
|
||||||
|
|
||||||
|
def do_3pidbind(self, line):
|
||||||
|
"""Validate and associate a third party ID
|
||||||
|
<sid> The session ID (sid) given to you in the response to requestToken
|
||||||
|
<clientSecret> The same clientSecret you supplied in requestToken
|
||||||
|
"""
|
||||||
|
args = self._parse(line, ['sid', 'clientSecret'])
|
||||||
|
|
||||||
|
postArgs = { 'sid' : args['sid'], 'clientSecret': args['clientSecret'] }
|
||||||
|
postArgs['mxid'] = self.config["user"]
|
||||||
|
|
||||||
|
reactor.callFromThread(self._do_3pidbind, postArgs)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _do_3pidbind(self, args):
|
||||||
|
url = self._identityServerUrl()+"/matrix/identity/api/v1/3pid/bind"
|
||||||
|
|
||||||
|
json_res = yield self.http_client.do_request("POST", url, data=urllib.urlencode(args), jsonreq=False,
|
||||||
|
headers={'Content-Type': ['application/x-www-form-urlencoded']})
|
||||||
|
print json_res
|
||||||
|
|
||||||
def do_join(self, line):
|
def do_join(self, line):
|
||||||
"""Joins a room: "join <roomid>" """
|
"""Joins a room: "join <roomid>" """
|
||||||
try:
|
try:
|
||||||
|
@ -79,7 +79,6 @@ angular.module('matrixService', [])
|
|||||||
return $http(request);
|
return $http(request);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/****** Home server API ******/
|
/****** Home server API ******/
|
||||||
prefix: prefixPath,
|
prefix: prefixPath,
|
||||||
@ -310,17 +309,25 @@ angular.module('matrixService', [])
|
|||||||
},
|
},
|
||||||
|
|
||||||
// hit the Identity Server for a 3PID request.
|
// hit the Identity Server for a 3PID request.
|
||||||
linkEmail: function(email) {
|
linkEmail: function(email, clientSecret, sendAttempt) {
|
||||||
var path = "/matrix/identity/api/v1/validate/email/requestToken"
|
var path = "/matrix/identity/api/v1/validate/email/requestToken"
|
||||||
var data = "clientSecret=abc123&email=" + encodeURIComponent(email);
|
var data = "clientSecret="+clientSecret+"&email=" + encodeURIComponent(email)+"&sendAttempt="+sendAttempt;
|
||||||
var headers = {};
|
var headers = {};
|
||||||
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||||
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
|
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
|
||||||
},
|
},
|
||||||
|
|
||||||
authEmail: function(userId, tokenId, code) {
|
authEmail: function(clientSecret, tokenId, code) {
|
||||||
var path = "/matrix/identity/api/v1/validate/email/submitToken";
|
var path = "/matrix/identity/api/v1/validate/email/submitToken";
|
||||||
var data = "token="+code+"&mxId="+encodeURIComponent(userId)+"&tokenId="+tokenId;
|
var data = "token="+code+"&sid="+tokenId+"&clientSecret="+clientSecret;
|
||||||
|
var headers = {};
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||||
|
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
|
||||||
|
},
|
||||||
|
|
||||||
|
bindEmail: function(userId, tokenId, clientSecret) {
|
||||||
|
var path = "/matrix/identity/api/v1/3pid/bind";
|
||||||
|
var data = "mxid="+encodeURIComponent(userId)+"&sid="+tokenId+"&clientSecret="+clientSecret;
|
||||||
var headers = {};
|
var headers = {};
|
||||||
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||||
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
|
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
|
||||||
@ -393,6 +400,7 @@ angular.module('matrixService', [])
|
|||||||
// Set a new config (Use saveConfig to actually store it permanently)
|
// Set a new config (Use saveConfig to actually store it permanently)
|
||||||
setConfig: function(newConfig) {
|
setConfig: function(newConfig) {
|
||||||
config = newConfig;
|
config = newConfig;
|
||||||
|
console.log("new IS: "+config.identityServer);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Commits config into permanent storage
|
// Commits config into permanent storage
|
||||||
|
@ -70,6 +70,7 @@ angular.module('LoginController', ['matrixService'])
|
|||||||
$scope.login = function() {
|
$scope.login = function() {
|
||||||
matrixService.setConfig({
|
matrixService.setConfig({
|
||||||
homeserver: $scope.account.homeserver,
|
homeserver: $scope.account.homeserver,
|
||||||
|
identityServer: $scope.account.identityServer,
|
||||||
user_id: $scope.account.user_id
|
user_id: $scope.account.user_id
|
||||||
});
|
});
|
||||||
// try to login
|
// try to login
|
||||||
@ -79,6 +80,7 @@ angular.module('LoginController', ['matrixService'])
|
|||||||
$scope.feedback = "Login successful.";
|
$scope.feedback = "Login successful.";
|
||||||
matrixService.setConfig({
|
matrixService.setConfig({
|
||||||
homeserver: $scope.account.homeserver,
|
homeserver: $scope.account.homeserver,
|
||||||
|
identityServer: $scope.account.identityServer,
|
||||||
user_id: response.data.user_id,
|
user_id: response.data.user_id,
|
||||||
access_token: response.data.access_token
|
access_token: response.data.access_token
|
||||||
});
|
});
|
||||||
|
@ -48,6 +48,8 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload',
|
|||||||
linkNewEmail: "", // the email entry box
|
linkNewEmail: "", // the email entry box
|
||||||
emailBeingAuthed: undefined, // to populate verification text
|
emailBeingAuthed: undefined, // to populate verification text
|
||||||
authTokenId: undefined, // the token id from the IS
|
authTokenId: undefined, // the token id from the IS
|
||||||
|
clientSecret: undefined, // our client secret
|
||||||
|
sendAttempt: 1,
|
||||||
emailCode: "", // the code entry box
|
emailCode: "", // the code entry box
|
||||||
linkedEmailList: matrixService.config().emailList // linked email list
|
linkedEmailList: matrixService.config().emailList // linked email list
|
||||||
};
|
};
|
||||||
@ -219,11 +221,27 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload',
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var generateClientSecret = function() {
|
||||||
|
var ret = "";
|
||||||
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
|
for (var i = 0; i < 32; i++) {
|
||||||
|
ret += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.linkEmail = function(email) {
|
$scope.linkEmail = function(email) {
|
||||||
matrixService.linkEmail(email).then(
|
if (email != $scope.linkedEmails.emailBeingAuthed) {
|
||||||
|
$scope.linkedEmails.clientSecret = generateClientSecret();
|
||||||
|
$scope.linkedEmails.sendAttempt = 1;
|
||||||
|
}
|
||||||
|
matrixService.linkEmail(email, $scope.linkedEmails.clientSecret, $scope.linkedEmails.sendAttempt).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
if (response.data.success === true) {
|
if (response.data.success === true) {
|
||||||
$scope.linkedEmails.authTokenId = response.data.tokenId;
|
$scope.linkedEmails.authTokenId = response.data.sid;
|
||||||
$scope.emailFeedback = "You have been sent an email.";
|
$scope.emailFeedback = "You have been sent an email.";
|
||||||
$scope.linkedEmails.emailBeingAuthed = email;
|
$scope.linkedEmails.emailBeingAuthed = email;
|
||||||
}
|
}
|
||||||
@ -243,18 +261,20 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload',
|
|||||||
$scope.emailFeedback = "You have not requested a code with this email.";
|
$scope.emailFeedback = "You have not requested a code with this email.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
matrixService.authEmail(matrixService.config().user_id, tokenId, code).then(
|
matrixService.authEmail(matrixService.config().user_id, tokenId, code, $scope.linkedEmails.clientSecret).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
if ("success" in response.data && response.data.success === false) {
|
if ("success" in response.data && response.data.success === false) {
|
||||||
$scope.emailFeedback = "Failed to authenticate email.";
|
$scope.emailFeedback = "Failed to authenticate email.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
matrixService.bindEmail(matrixService.config().user_id, tokenId, $scope.linkedEmails.clientSecret).then(
|
||||||
|
function(response) {
|
||||||
var config = matrixService.config();
|
var config = matrixService.config();
|
||||||
var emailList = {};
|
var emailList = {};
|
||||||
if ("emailList" in config) {
|
if ("emailList" in config) {
|
||||||
emailList = config.emailList;
|
emailList = config.emailList;
|
||||||
}
|
}
|
||||||
emailList[response.address] = response;
|
emailList[$scope.linkedEmails.emailBeingAuthed] = response;
|
||||||
// save the new email list
|
// save the new email list
|
||||||
config.emailList = emailList;
|
config.emailList = emailList;
|
||||||
matrixService.setConfig(config);
|
matrixService.setConfig(config);
|
||||||
@ -265,6 +285,10 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload',
|
|||||||
$scope.linkedEmails.linkedEmailList = emailList;
|
$scope.linkedEmails.linkedEmailList = emailList;
|
||||||
$scope.linkedEmails.linkNewEmail = "";
|
$scope.linkedEmails.linkNewEmail = "";
|
||||||
$scope.linkedEmails.emailCode = "";
|
$scope.linkedEmails.emailCode = "";
|
||||||
|
}, function(reason) {
|
||||||
|
$scope.emailFeedback = "Failed to link email: " + reason;
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function(reason) {
|
function(reason) {
|
||||||
$scope.emailFeedback = "Failed to auth email: " + reason;
|
$scope.emailFeedback = "Failed to auth email: " + reason;
|
||||||
|
Loading…
Reference in New Issue
Block a user