Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for stable MSC3882 get_login_token #1791

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,10 @@
EDDBA7F1293F353900AD1480 /* MXToDevicePayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDBA7EF293F353900AD1480 /* MXToDevicePayload.swift */; };
EDDD90C82901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */; };
EDDD90C92901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */; };
EDDE8B812A272B8200EBEADB /* MXLoginTokenFlow.m in Sources */ = {isa = PBXBuildFile; fileRef = EDDE8B802A272B8200EBEADB /* MXLoginTokenFlow.m */; };
EDDE8B822A272B8200EBEADB /* MXLoginTokenFlow.m in Sources */ = {isa = PBXBuildFile; fileRef = EDDE8B802A272B8200EBEADB /* MXLoginTokenFlow.m */; };
EDDE8B832A2738AD00EBEADB /* MXLoginTokenFlow.h in Headers */ = {isa = PBXBuildFile; fileRef = EDDE8B7F2A272A0F00EBEADB /* MXLoginTokenFlow.h */; settings = {ATTRIBUTES = (Public, ); }; };
EDDE8B842A2738AE00EBEADB /* MXLoginTokenFlow.h in Headers */ = {isa = PBXBuildFile; fileRef = EDDE8B7F2A272A0F00EBEADB /* MXLoginTokenFlow.h */; settings = {ATTRIBUTES = (Public, ); }; };
EDE1B13B28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDE1B13A28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift */; };
EDE1B13C28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDE1B13A28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift */; };
EDE70DC528DA1B7F00099736 /* MXCryptoTools.h in Headers */ = {isa = PBXBuildFile; fileRef = 3250E7C8220C913900736CB5 /* MXCryptoTools.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -3219,6 +3223,8 @@
EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoV2FactoryUnitTests.swift; sourceTree = "<group>"; };
EDDBA7EF293F353900AD1480 /* MXToDevicePayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXToDevicePayload.swift; sourceTree = "<group>"; };
EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MXLegacyCrypto+LegacyCrossSigning.swift"; sourceTree = "<group>"; };
EDDE8B7F2A272A0F00EBEADB /* MXLoginTokenFlow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXLoginTokenFlow.h; sourceTree = "<group>"; };
EDDE8B802A272B8200EBEADB /* MXLoginTokenFlow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXLoginTokenFlow.m; sourceTree = "<group>"; };
EDE1B13A28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCrossSigningV2UnitTests.swift; sourceTree = "<group>"; };
EDE70DC728DA22F800099736 /* MXKeyBackupEngine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXKeyBackupEngine.h; sourceTree = "<group>"; };
EDF154E0296C203E004D7FFE /* MXCryptoMachineStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMachineStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4865,6 +4871,8 @@
B14EECD62577DE7A00448735 /* MXLoginSSOIdentityProvider.m */,
B14EECE32577F76100448735 /* MXLoginSSOFlow.h */,
B14EECE42577F76100448735 /* MXLoginSSOFlow.m */,
EDDE8B7F2A272A0F00EBEADB /* MXLoginTokenFlow.h */,
EDDE8B802A272B8200EBEADB /* MXLoginTokenFlow.m */,
);
path = Login;
sourceTree = "<group>";
Expand Down Expand Up @@ -6055,6 +6063,7 @@
32133025228BFA800070BA9B /* MXReactionCountChangeListener.h in Headers */,
321CFDFB2254E728004D31DF /* MXTransactionCancelCode.h in Headers */,
32A9770421626E5C00919CC0 /* MXServerNotices.h in Headers */,
EDDE8B832A2738AD00EBEADB /* MXLoginTokenFlow.h in Headers */,
91CC0FCA26A033AE00C2A387 /* MXURLPreview.h in Headers */,
021AFBA42179E91900742B2C /* MXEncryptedContentFile.h in Headers */,
B146D4F021A5AF7F00D8C2C6 /* MXRealmEventScanMapper.h in Headers */,
Expand Down Expand Up @@ -6547,6 +6556,7 @@
B14EF3242397E90400758AF0 /* MXBugReportRestClient.h in Headers */,
323F877C25546170009E9E67 /* MXBaseProfiler.h in Headers */,
B14EF3252397E90400758AF0 /* MXRoomPowerLevels.h in Headers */,
EDDE8B842A2738AE00EBEADB /* MXLoginTokenFlow.h in Headers */,
B19A309F240424BD00FB6F35 /* MXQRCodeTransaction_Private.h in Headers */,
3AC13803264482A100EE1E74 /* MXExportedOlmDevice.h in Headers */,
B14EF3262397E90400758AF0 /* MXEventScanStoreDelegate.h in Headers */,
Expand Down Expand Up @@ -7374,6 +7384,7 @@
32F9FA7E1DBA0CF0009D98A6 /* MXDecryptionResult.m in Sources */,
321CFDF92254E721004D31DF /* MXTransactionCancelCode.m in Sources */,
B19A30C22404268600FB6F35 /* MXVerifyingAnotherUserQRCodeData.m in Sources */,
EDDE8B822A272B8200EBEADB /* MXLoginTokenFlow.m in Sources */,
EC8A53BD25B1BC77004E0802 /* MXCallRejectEventContent.m in Sources */,
EC6D007B28E1F15400152144 /* MXDevice.m in Sources */,
EDCB65E22912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */,
Expand Down Expand Up @@ -8046,6 +8057,7 @@
B14EF2802397E90400758AF0 /* MXServiceTerms.m in Sources */,
3229535425A5F7220012FCF0 /* MXBackgroundCryptoStore.m in Sources */,
B14EF2812397E90400758AF0 /* MXNotificationCenter.m in Sources */,
EDDE8B812A272B8200EBEADB /* MXLoginTokenFlow.m in Sources */,
EC60ED60265CFC2C00B39A4E /* MXSyncResponse.m in Sources */,
EC6D007C28E1F15400152144 /* MXDevice.m in Sources */,
EDCB65E32912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions MatrixSDK/JSONModels/Capabilities/MXCapabilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
static NSString* const kJSONKeySetDisplayName = @"m.set_displayname";
static NSString* const kJSONKeySetAvatarUrl = @"m.set_avatar_url";
static NSString* const kJSONKeyThreePidChanges = @"m.3pid_changes";
static NSString* const kJSONKeyGetLoginToken = @"m.get_login_token";

@interface MXCapabilities ()

Expand All @@ -33,6 +34,7 @@ @interface MXCapabilities ()
@property (nonatomic, readwrite, nullable) MXBooleanCapability *setDisplayName;
@property (nonatomic, readwrite, nullable) MXBooleanCapability *setAvatarUrl;
@property (nonatomic, readwrite, nullable) MXBooleanCapability *threePidChanges;
@property (nonatomic, readwrite, nullable) MXBooleanCapability *getLoginToken;

@end

Expand All @@ -52,6 +54,7 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
MXJSONModelSetMXJSONModel(result.setDisplayName, MXBooleanCapability, capabilities[kJSONKeySetDisplayName]);
MXJSONModelSetMXJSONModel(result.setAvatarUrl, MXBooleanCapability, capabilities[kJSONKeySetAvatarUrl]);
MXJSONModelSetMXJSONModel(result.threePidChanges, MXBooleanCapability, capabilities[kJSONKeyThreePidChanges]);
MXJSONModelSetMXJSONModel(result.getLoginToken, MXBooleanCapability, capabilities[kJSONKeyGetLoginToken]);

return result;
}
Expand Down Expand Up @@ -79,6 +82,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
MXJSONModelSetMXJSONModel(self.setDisplayName, MXBooleanCapability, self.allCapabilities[kJSONKeySetDisplayName]);
MXJSONModelSetMXJSONModel(self.setAvatarUrl, MXBooleanCapability, self.allCapabilities[kJSONKeySetAvatarUrl]);
MXJSONModelSetMXJSONModel(self.threePidChanges, MXBooleanCapability, self.allCapabilities[kJSONKeyThreePidChanges]);
MXJSONModelSetMXJSONModel(self.getLoginToken, MXBooleanCapability, self.allCapabilities[kJSONKeyGetLoginToken]);
}
return self;
}
Expand Down
37 changes: 37 additions & 0 deletions MatrixSDK/JSONModels/Login/MXLoginTokenFlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright 2023 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/Foundation.h>
#import "MXJSONModels.h"

NS_ASSUME_NONNULL_BEGIN

extern NSString *const MXLoginTokenFlowGetLoginTokenKey;

/**
`MXLoginTokenFlow` represents a login token flow supported by the home server: https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3login
*/
@interface MXLoginTokenFlow : MXLoginFlow

/**

If true then the POST /login/get_token may be available to the user.
*/
@property (nonatomic, readonly) BOOL getLoginToken;

@end

NS_ASSUME_NONNULL_END
41 changes: 41 additions & 0 deletions MatrixSDK/JSONModels/Login/MXLoginTokenFlow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright 2023 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 "MXLoginTokenFlow.h"

NSString *const MXLoginTokenFlowGetLoginTokenKey = @"get_login_token";

@interface MXLoginTokenFlow()

@property (nonatomic, readwrite) BOOL getLoginToken;

@end

@implementation MXLoginTokenFlow

+ (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXLoginTokenFlow *loginFlow = [super modelFromJSON:JSONDictionary];

if (loginFlow)
{
MXJSONModelSetBoolean(loginFlow.getLoginToken, JSONDictionary[MXLoginTokenFlowGetLoginTokenKey]);
}

return loginFlow;
}

@end
4 changes: 2 additions & 2 deletions MatrixSDK/JSONModels/MXJSONModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,13 @@ FOUNDATION_EXPORT NSString *const kMXPresenceOffline;
@end

/**
`MXLoginToken` represents the response of a /login/token creation request
`MXLoginToken` represents the response of a /login/get_token creation request
*/
@interface MXLoginToken : MXJSONModel

@property (nonatomic) NSString *token;

@property (nonatomic) uint64_t expiresIn;
@property (nonatomic) uint64_t expiresInMs;

@end

Expand Down
7 changes: 6 additions & 1 deletion MatrixSDK/JSONModels/MXJSONModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "MXCrossSigningInfo_Private.h"
#import "MXKey.h"
#import "MXLoginSSOFlow.h"
#import "MXLoginTokenFlow.h"

#pragma mark - Local constants

Expand Down Expand Up @@ -203,6 +204,10 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
loginFlow = [MXLoginSSOFlow modelFromJSON:JSONDictionary];
}
else if ([type isEqualToString:kMXLoginFlowTypeToken])
{
loginFlow = [MXLoginTokenFlow modelFromJSON:JSONDictionary];
}
else
{
loginFlow = [MXLoginFlow modelFromJSON:JSONDictionary];
Expand Down Expand Up @@ -596,7 +601,7 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary
if (loginToken)
{
MXJSONModelSetString(loginToken.token, JSONDictionary[@"login_token"]);
MXJSONModelSetUInt64(loginToken.expiresIn, JSONDictionary[@"expires_in"]);
MXJSONModelSetUInt64(loginToken.expiresInMs, JSONDictionary[@"expires_in_ms"]);

MXJSONModelSetDictionary(loginToken.json, JSONDictionary);
}
Expand Down
3 changes: 2 additions & 1 deletion MatrixSDK/JSONModels/MXMatrixVersions.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ extern const struct MXMatrixVersionsFeatureStruct MXMatrixVersionsFeature;

/**
Indicate if the server supports logging in via a QR
@deprecated The availability of get_login_token/MSC3882 is now exposed as a capability and/or part of login flow in stable 1.7
*/
@property (nonatomic, readonly) BOOL supportsQRLogin;
@property (nonatomic, readonly) BOOL supportsQRLogin __deprecated_msg("Use capability and/or login flow instead");

/**
Indicate if the server supports notifications for threads (MSC3773)
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ - (MXHTTPOperation*)generateLoginTokenWithSuccess:(void (^)(MXLoginToken *))succ
{
MXWeakify(self);
return [httpClient requestWithMethod:@"POST"
path:[NSString stringWithFormat:@"%@/org.matrix.msc3882/login/token", kMXAPIPrefixPathUnstable]
path:[NSString stringWithFormat:@"%@/login/get_token", kMXAPIPrefixPathV1]
parameters:@{}
success:^(NSDictionary *JSONResponse) {
MXStrongifyAndReturnIfNil(self);
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/MatrixSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ FOUNDATION_EXPORT NSString *MatrixSDKVersion;
#import "MXThirdPartyUsersResponse.h"

#import "MXLoginSSOFlow.h"
#import "MXLoginTokenFlow.h"

#import "MXKeyProvider.h"
#import "MXAesKeyData.h"
Expand Down
17 changes: 15 additions & 2 deletions MatrixSDKTests/MXAuthenticationSessionUnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class MXAuthenticationSessionUnitTests: XCTestCase {
["type": "m.login.cas",
"stages": [],
"identity_providers": []
],
["type": "m.login.token",
"get_login_token": true
]
],
"params": [
Expand All @@ -57,7 +60,7 @@ class MXAuthenticationSessionUnitTests: XCTestCase {
return
}

XCTAssertEqual(flows.count, 3)
XCTAssertEqual(flows.count, 4)

if let ssoFlow = flows.first(where: { $0.type == kMXLoginFlowTypeSSO }) {

Expand Down Expand Up @@ -109,6 +112,16 @@ class MXAuthenticationSessionUnitTests: XCTestCase {
} else {
XCTFail("Fail to find password flow")
}


if let tokenFlow = flows.first(where: { $0.type == kMXLoginFlowTypeToken }) {

if let loginTokenFlow = tokenFlow as? MXLoginTokenFlow {
XCTAssertEqual(loginTokenFlow.getLoginToken, true)
} else {
XCTFail("The token flow is not member of class MXLoginTokenFlow")
}
} else {
XCTFail("Fail to find login token flow")
}
}
}
1 change: 1 addition & 0 deletions changelog.d/pr-1791.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for discovery of availability of stable MSC3882 get_login_token.