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

Commit

Permalink
MXK3PID: Privacy: Sending Third-Party Request Tokens via the Homeserver
Browse files Browse the repository at this point in the history
This implements ([MSC2078](matrix-org/matrix-spec-proposals#2078)).
This is a quick c+p from matrix-org/matrix-ios-sdk#728.
We will completely remove MXK3PID when refactoring login/registration.
  • Loading branch information
manuroe committed Oct 8, 2019
1 parent 8a0ca8e commit b95efaa
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 b95efaa

Please sign in to comment.