Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

MXK3PID: Privacy: Sending Third-Party Request Tokens via the Homeserver #611

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions MatrixKit/Models/MXK3PID.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @interface MXK3PID ()
@property (nonatomic) NSUInteger sendAttempt;
@property (nonatomic) NSString *sid;
@property (nonatomic) MXIdentityService *identityService;
@property (nonatomic) NSString *submitUrl;

@end

Expand Down Expand Up @@ -120,11 +121,12 @@ - (void)requestValidationTokenWithMatrixRestClient:(MXRestClient*)restClient

NSString *phoneNumber = [NSString stringWithFormat:@"+%@", self.address];

currentRequest = [mxRestClient requestTokenForPhoneNumber:phoneNumber isDuringRegistration:isDuringRegistration countryCode:nil clientSecret:self.clientSecret sendAttempt:self.sendAttempt nextLink:nextLink success:^(NSString *sid, NSString *msisdn) {
currentRequest = [mxRestClient requestTokenForPhoneNumber:phoneNumber isDuringRegistration:isDuringRegistration countryCode:nil clientSecret:self.clientSecret sendAttempt:self.sendAttempt nextLink:nextLink success:^(NSString *sid, NSString *msisdn, NSString *submitUrl) {

self->_validationState = MXK3PIDAuthStateTokenReceived;
self->currentRequest = nil;
self.sid = sid;
self.submitUrl = submitUrl;

if (success)
{
Expand Down Expand Up @@ -164,7 +166,34 @@ - (void)submitValidationToken:(NSString *)token
// Sanity Check
if (_validationState == MXK3PIDAuthStateTokenReceived)
{
if (self.identityService)
if (self.submitUrl)
{
_validationState = MXK3PIDAuthStateTokenSubmitted;

currentRequest = [self submitMsisdnTokenOtherUrl:self.submitUrl token:token medium:self.medium clientSecret:self.clientSecret sid:self.sid success:^{

self->_validationState = MXK3PIDAuthStateAuthenticated;
self->currentRequest = nil;

if (success)
{
success();
}

} failure:^(NSError *error) {

// Return in previous state
self->_validationState = MXK3PIDAuthStateTokenReceived;
self->currentRequest = nil;

if (failure)
{
failure (error);
}

}];
}
else if (self.identityService)
{
_validationState = MXK3PIDAuthStateTokenSubmitted;

Expand Down Expand Up @@ -212,6 +241,30 @@ - (void)submitValidationToken:(NSString *)token
}
}

- (MXHTTPOperation *)submitMsisdnTokenOtherUrl:(NSString *)url
token:(NSString*)token
medium:(NSString *)medium
clientSecret:(NSString *)clientSecret
sid:(NSString *)sid
success:(void (^)(void))success
failure:(void (^)(NSError *))failure
{
NSDictionary *parameters = @{
@"sid": sid,
@"client_secret": clientSecret,
@"token": token
};

MXHTTPClient *httpClient = [[MXHTTPClient alloc] initWithBaseURL:nil andOnUnrecognizedCertificateBlock:nil];
return [httpClient requestWithMethod:@"POST"
path:url
parameters:parameters
success:^(NSDictionary *JSONResponse) {
success();
}
failure:failure];
}

- (void)add3PIDToUser:(BOOL)bind
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
Expand Down