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

Commit

Permalink
Merge pull request #611 from matrix-org/riot_2731
Browse files Browse the repository at this point in the history
MXK3PID: Privacy: Sending Third-Party Request Tokens via the Homeserver
  • Loading branch information
manuroe authored Oct 8, 2019
2 parents 95f805c + b95efaa commit 3859700
Showing 1 changed file with 55 additions and 2 deletions.
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

0 comments on commit 3859700

Please sign in to comment.