Skip to content

Commit

Permalink
Merge pull request #726 from matrix-org/riot_2718
Browse files Browse the repository at this point in the history
[WIP] MX3PidAddManager: New class to handle add 3pids to HS and to bind to IS
  • Loading branch information
manuroe authored Oct 4, 2019
2 parents b2530cf + eb9b39e commit d7fa394
Show file tree
Hide file tree
Showing 14 changed files with 1,431 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes in Matrix iOS SDK in 0.13.2 (2019-08-)
Improvements:
* MXServiceTerms: A class to support MSC2140 (Terms of Service API) (vector-im/riot-ios#2600).
* MXRestClient: Remove identity server URL fallback to homeserver one's when there is no identity server configured.
* MXRestClient: Add new APIs from MSC2290 (matrix-org/matrix-doc/pull/2290).
* MXHTTPClient: Improve M_LIMIT_EXCEEDED error handling: Do not wait to try again if the mentioned delay is too long.
* MXEventTimeline: The roomEventFilter property is now writable (vector-im/riot-ios#2615).
* VoIP: Make call start if there is no STUN server.
Expand All @@ -14,10 +15,11 @@ Improvements:
* MXHTTPClient: Add access token renewal plus request retry mechanism.
* MXHTTPClient: Do not retry requests if the host is not valid.
* MXAutoDiscovery: Add initWithUrl contructor.
* MX3PidAddManager: New class to handle add 3pids to HS and to bind to IS.
* Privacy: Store Identity Server in Account Data ([MSC2230](https://github.com/matrix-org/matrix-doc/pull/2230))(vector-im/riot-ios#2665).
* Privacy: Lowercase emails during IS lookup calls (vector-im/riot-ios#2696).
* Privacy: MXRestClient: Use `id_access_token` in CS API when required (vector-im/riot-ios#2704).


API break:
* MXRestClient: Remove identity server requests. Now MXIdentityService is used to perform identity server requests.
Expand Down
36 changes: 36 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@
32CAB10C1A925B41008C5BB9 /* MXHTTPOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CAB10A1A925B41008C5BB9 /* MXHTTPOperation.m */; };
32CE6FB81A409B1F00317F1E /* MXFileStoreMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 32CE6FB61A409B1F00317F1E /* MXFileStoreMetaData.h */; };
32CE6FB91A409B1F00317F1E /* MXFileStoreMetaData.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CE6FB71A409B1F00317F1E /* MXFileStoreMetaData.m */; };
32D2CC0323422462002BD8CA /* MX3PidAddSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D2CBFF23422462002BD8CA /* MX3PidAddSession.m */; };
32D2CC0423422462002BD8CA /* MX3PidAddManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D2CC0023422462002BD8CA /* MX3PidAddManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D2CC0523422462002BD8CA /* MX3PidAddSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D2CC0123422462002BD8CA /* MX3PidAddSession.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D2CC0623422462002BD8CA /* MX3PidAddManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D2CC0223422462002BD8CA /* MX3PidAddManager.m */; };
32D2CC09234336D6002BD8CA /* MX3PidAddManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D2CC08234336D6002BD8CA /* MX3PidAddManager.swift */; };
32D7767D1A27860600FC4AA2 /* MXMemoryStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D7767B1A27860600FC4AA2 /* MXMemoryStore.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D7767E1A27860600FC4AA2 /* MXMemoryStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D7767C1A27860600FC4AA2 /* MXMemoryStore.m */; };
32D776811A27877300FC4AA2 /* MXMemoryRoomStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D7767F1A27877300FC4AA2 /* MXMemoryRoomStore.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -813,6 +818,11 @@
32CAB10A1A925B41008C5BB9 /* MXHTTPOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXHTTPOperation.m; sourceTree = "<group>"; };
32CE6FB61A409B1F00317F1E /* MXFileStoreMetaData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXFileStoreMetaData.h; sourceTree = "<group>"; };
32CE6FB71A409B1F00317F1E /* MXFileStoreMetaData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXFileStoreMetaData.m; sourceTree = "<group>"; };
32D2CBFF23422462002BD8CA /* MX3PidAddSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MX3PidAddSession.m; sourceTree = "<group>"; };
32D2CC0023422462002BD8CA /* MX3PidAddManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MX3PidAddManager.h; sourceTree = "<group>"; };
32D2CC0123422462002BD8CA /* MX3PidAddSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MX3PidAddSession.h; sourceTree = "<group>"; };
32D2CC0223422462002BD8CA /* MX3PidAddManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MX3PidAddManager.m; sourceTree = "<group>"; };
32D2CC08234336D6002BD8CA /* MX3PidAddManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MX3PidAddManager.swift; sourceTree = "<group>"; };
32D7767B1A27860600FC4AA2 /* MXMemoryStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXMemoryStore.h; sourceTree = "<group>"; };
32D7767C1A27860600FC4AA2 /* MXMemoryStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXMemoryStore.m; sourceTree = "<group>"; };
32D7767F1A27877300FC4AA2 /* MXMemoryRoomStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXMemoryRoomStore.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1665,6 +1675,7 @@
3281E8B219E42DFE00976E1A /* JSONModels */,
32DC15CA1A8CF7AE006F9AD3 /* NotificationCenter */,
3294FD9822F321B0007F1E60 /* ServiceTerms */,
32D2CBFE23422462002BD8CA /* ThreePidAdd */,
320DFDD619DD99B60068622A /* Utils */,
3245A74B1AF7B2930001D8A7 /* VoIP */,
32A151581DB5254D00400192 /* Lib */,
Expand Down Expand Up @@ -1761,6 +1772,25 @@
name = "Supporting Files";
sourceTree = "<group>";
};
32D2CBFE23422462002BD8CA /* ThreePidAdd */ = {
isa = PBXGroup;
children = (
32D2CC0023422462002BD8CA /* MX3PidAddManager.h */,
32D2CC0223422462002BD8CA /* MX3PidAddManager.m */,
32D2CC0123422462002BD8CA /* MX3PidAddSession.h */,
32D2CBFF23422462002BD8CA /* MX3PidAddSession.m */,
);
path = ThreePidAdd;
sourceTree = "<group>";
};
32D2CC0723433684002BD8CA /* ThreePidAdd */ = {
isa = PBXGroup;
children = (
32D2CC08234336D6002BD8CA /* MX3PidAddManager.swift */,
);
path = ThreePidAdd;
sourceTree = "<group>";
};
32D7767A1A2785CE00FC4AA2 /* MXMemoryStore */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1972,6 +2002,7 @@
C6F9357A1E5B391B00FC34BF /* Swift */ = {
isa = PBXGroup;
children = (
32D2CC0723433684002BD8CA /* ThreePidAdd */,
C6F935821E5B3BE600FC34BF /* Data */,
C6F935851E5B3BE600FC34BF /* JSONModels */,
C6F9357E1E5B3ACA00FC34BF /* MXResponse.swift */,
Expand Down Expand Up @@ -2111,6 +2142,7 @@
32F9FA7D1DBA0CF0009D98A6 /* MXDecryptionResult.h in Headers */,
3245A7501AF7B2930001D8A7 /* MXCall.h in Headers */,
02CAD43B217DD12F0074700B /* MXContentScanEncryptedBody.h in Headers */,
32D2CC0423422462002BD8CA /* MX3PidAddManager.h in Headers */,
3271877D1DA7CB2F0071C818 /* MXDecrypting.h in Headers */,
32114A851A262CE000FF2EC4 /* MXStore.h in Headers */,
32BA86AF2152A79E008F277E /* MXRoomNameDefaultStringLocalizations.h in Headers */,
Expand Down Expand Up @@ -2227,6 +2259,7 @@
3275FD9C21A6B60B00B9C13D /* MXLoginPolicy.h in Headers */,
3250E7CA220C913900736CB5 /* MXCryptoTools.h in Headers */,
F0173EAC1FCF0E8900B5F6A3 /* MXGroup.h in Headers */,
32D2CC0523422462002BD8CA /* MX3PidAddSession.h in Headers */,
329FB17F1A0B665800A5E88E /* MXUser.h in Headers */,
320DFDE219DD99B60068622A /* MXError.h in Headers */,
B11BD45922CB58850064D8B0 /* MXReplyEventFormattedBodyParts.h in Headers */,
Expand Down Expand Up @@ -2447,8 +2480,10 @@
327E9ABD2284521C00A98BC1 /* MXEventUnsignedData.m in Sources */,
32A1513A1DAD292400400192 /* MXMegolmEncryption.m in Sources */,
32F945F71FAB83D900622468 /* MXIncomingRoomKeyRequest.m in Sources */,
32D2CC09234336D6002BD8CA /* MX3PidAddManager.swift in Sources */,
F0173EAD1FCF0E8900B5F6A3 /* MXGroup.m in Sources */,
32720D9F222EAA6F0086FFF5 /* MXAutoDiscovery.m in Sources */,
32D2CC0623422462002BD8CA /* MX3PidAddManager.m in Sources */,
92634B831EF2E3C400DB9F60 /* MXCallKitConfiguration.m in Sources */,
3265CB391A14C43E00E24B2F /* MXRoomState.m in Sources */,
3281E8B819E42DFE00976E1A /* MXJSONModel.m in Sources */,
Expand Down Expand Up @@ -2488,6 +2523,7 @@
3250E7CB220C913900736CB5 /* MXCryptoTools.m in Sources */,
3252DCBE224D144C0032264F /* MXKeyVerificationAccept.m in Sources */,
322691331E5EF77D00966A6E /* MXDeviceListOperation.m in Sources */,
32D2CC0323422462002BD8CA /* MX3PidAddSession.m in Sources */,
3283F7791EAF30F700C1688C /* MXBugReportRestClient.m in Sources */,
B1798304211B3649001FD722 /* MXRoomSummary.swift in Sources */,
9274AFE91EE580240009BEB6 /* MXCallKitAdapter.m in Sources */,
Expand Down
63 changes: 62 additions & 1 deletion MatrixSDK/Contrib/Swift/MXRestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,9 @@ public extension MXRestClient {

/**
Link an authenticated 3rd party id to the Matrix user.
This API is deprecated, and you should instead use `addThirdPartyIdentifierOnly`
for homeservers that support it.
- parameters:
- sid: the id provided during the 3PID validation session (MXRestClient.requestEmailValidation).
Expand All @@ -1365,6 +1368,27 @@ public extension MXRestClient {
@nonobjc @discardableResult func addThirdPartyIdentifier(_ sid: String, clientSecret: String, bind: Bool, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __add3PID(sid, clientSecret: clientSecret, bind: bind, success: currySuccess(completion), failure: curryFailure(completion))
}

/**
Add a 3PID to your homeserver account.
This API does not use an identity server, as the homeserver is expected to
handle 3PID ownership validation.
You can check whether a homeserver supports this API via
`doesServerSupportSeparateAddAndBind`.
- parameters:
- sid: the session id provided during the 3PID validation session.
- clientSecret: the same secret key used in the validation session.
- completion: A block object called when the operation completes.
- response: Indicates whether the operation was successful.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func addThirdPartyIdentifierOnly(withSessionId sid: String, clientSecret: String, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __add3PIDOnly(withSessionId: sid, clientSecret: clientSecret, success: currySuccess(completion), failure: curryFailure(completion))
}

/**
Remove a 3rd party id from the Matrix user information.
Expand Down Expand Up @@ -1393,7 +1417,44 @@ public extension MXRestClient {
@nonobjc @discardableResult func thirdPartyIdentifiers(_ completion: @escaping (_ response: MXResponse<[MXThirdPartyIdentifier]?>) -> Void) -> MXHTTPOperation {
return __threePIDs(currySuccess(completion), failure: curryFailure(completion))
}


/**
Bind a 3PID for discovery onto an identity server via the homeserver.
The identity server handles 3PID ownership validation and the homeserver records
the new binding to track where all 3PIDs for the account are bound.
You can check whether a homeserver supports this API via
`doesServerSupportSeparateAddAndBind`.
- parameters:
- sid: the session id provided during the 3PID validation session.
- clientSecret: the same secret key used in the validation session.
- completion: A block object called when the operation completes.
- response: Indicates whether the operation was successful.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func bind3Pid(withSessionId sid: String, clientSecret: String, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __bind3Pid(withSessionId: sid, clientSecret: clientSecret, success: currySuccess(completion), failure: curryFailure(completion))
}

/**
Unbind a 3PID for discovery on an identity server via the homeserver.
- parameters:
- address: the 3rd party id.
- medium: medium the type of the 3rd party id.
- completion: A block object called when the operation completes.
- response: Indicates whether the operation was successful.
- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func unbind3Pid(withAddress address: String, medium: String, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MXHTTPOperation {
return __unbind3Pid(withAddress: address, medium: medium, success: currySuccess(completion), failure: curryFailure(completion))
}



// MARK: - Presence operations

Expand Down
67 changes: 67 additions & 0 deletions MatrixSDK/Contrib/Swift/ThreePidAdd/MX3PidAddManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

public extension MX3PidAddManager {

// MARK: - Setup
@nonobjc convenience init(session: MXSession) {
self.init(__matrixSession: session)
}

@nonobjc func cancel(session: MX3PidAddSession) {
__cancel3PidAddSession(session)
}

// MARK: - Email
@nonobjc @discardableResult func startAddEmailSession(_ email: String, nextLink: String?, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MX3PidAddSession {
return __startAddEmailSession(withEmail: email, nextLink: nextLink, success: currySuccess(completion), failure: curryFailure(completion))
}

@nonobjc func tryFinaliseAddEmailSession(_ session: MX3PidAddSession, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> Void {
return __tryFinaliseAddEmailSession(session, success: currySuccess(completion), failure: curryFailure(completion))
}


// MARK: - Add MSISDN
@nonobjc @discardableResult func startAddPhoneNumberSession(_ phoneNumber: String, countryCode: String?, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> MX3PidAddSession {
return __startAddPhoneNumberSession(withPhoneNumber: phoneNumber, countryCode: countryCode, success: currySuccess(completion), failure: curryFailure(completion))
}

@nonobjc func finaliseAddPhoneNumberSession(_ session: MX3PidAddSession, token: String, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> Void {
return __finaliseAddPhoneNumber(session, withToken: token, success: currySuccess(completion), failure: curryFailure(completion))
}


// MARK: - Bind Email
@nonobjc @discardableResult func startIdentityServerSession(withEmail email: String, bind: Bool, completion: @escaping (_ response: MXResponse<Bool>) -> Void) -> MX3PidAddSession {
return __startIdentityServerEmailSession(withEmail: email, bind: bind, success: currySuccess(completion), failure: curryFailure(completion))
}

@nonobjc func tryFinaliseIdentityServerEmailSession(_ session: MX3PidAddSession, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> Void {
return __tryFinaliseIdentityServerEmailSession(session, success: currySuccess(completion), failure: curryFailure(completion))
}

// MARK: - Bind phone number
@nonobjc @discardableResult func startIdentityServerSession(withPhoneNumber phoneNumber: String, countryCode: String?, bind: Bool, completion: @escaping (_ response: MXResponse<Bool>) -> Void) -> MX3PidAddSession {
return __startIdentityServerPhoneNumberSession(withPhoneNumber: phoneNumber, countryCode: countryCode, bind: bind, success: currySuccess(completion), failure: curryFailure(completion))
}

@nonobjc func finaliseIdentityServerPhoneNumberSession(_ session: MX3PidAddSession, token: String, completion: @escaping (_ response: MXResponse<Void>) -> Void) -> Void {
return __finaliseIdentityServerPhoneNumber(session, withToken: token, success: currySuccess(completion), failure: curryFailure(completion))
}
}
12 changes: 11 additions & 1 deletion MatrixSDK/IdentityServer/MXIdentityService.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,17 @@ - (MXHTTPOperation*)accountWithSuccess:(void (^)(NSString *userId))success
failure:(void (^)(NSError *error))failure
{
return [self checkAPIVersionAvailabilityAndPerformOperationOnSuccess:^MXHTTPOperation* {
return [self.restClient accountWithSuccess:success failure:failure];
if (self.restClient.preferredAPIPathPrefix == kMXIdentityAPIPrefixPathV2)
{
return [self.restClient accountWithSuccess:success failure:failure];
}
else
{
// There is no account in v1
success(nil);
return nil;
}

} failure:failure];
}

Expand Down
Loading

0 comments on commit d7fa394

Please sign in to comment.