Skip to content
Merged
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Changes to be released in next version
*

🙌 Improvements
*
* Login flow: Add MXLoginSSOFlow to support multiple SSO Identity Providers ([MSC2858](https://github.com/matrix-org/matrix-doc/pull/2858)) (vector-im/element-ios/issues/3846).

🐛 Bugfix
*

⚠️ API Changes
*
* Add MXLoginSSOFlow which represents a SSO login flow and offers multiple SSO Identity Providers through MXLoginSSOIdentityProvider class.
Copy link
Contributor

@manuroe manuroe Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use the API changes section for api breaks.
It will be annoying if we start to describe every new api here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this

* MXAuthenticationSession: `flows` property which represents all supported login flows now handles MXLoginFlow and MXLoginSSOFlow classes.

🗣 Translations
*
Expand Down
38 changes: 38 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,16 @@
B14766B823D9D9410091F721 /* MXUsersTrustLevelSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = B14766B523D9D9410091F721 /* MXUsersTrustLevelSummary.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14766B923D9D9420091F721 /* MXUsersTrustLevelSummary.m in Sources */ = {isa = PBXBuildFile; fileRef = B14766B623D9D9410091F721 /* MXUsersTrustLevelSummary.m */; };
B14766BA23D9D9420091F721 /* MXUsersTrustLevelSummary.m in Sources */ = {isa = PBXBuildFile; fileRef = B14766B623D9D9410091F721 /* MXUsersTrustLevelSummary.m */; };
B14EECD72577DE7A00448735 /* MXLoginSSOIdentityProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = B14EECD52577DE7A00448735 /* MXLoginSSOIdentityProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EECD82577DE7A00448735 /* MXLoginSSOIdentityProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = B14EECD52577DE7A00448735 /* MXLoginSSOIdentityProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EECD92577DE7A00448735 /* MXLoginSSOIdentityProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = B14EECD62577DE7A00448735 /* MXLoginSSOIdentityProvider.m */; };
B14EECDA2577DE7B00448735 /* MXLoginSSOIdentityProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = B14EECD62577DE7A00448735 /* MXLoginSSOIdentityProvider.m */; };
B14EECE52577F76100448735 /* MXLoginSSOFlow.h in Headers */ = {isa = PBXBuildFile; fileRef = B14EECE32577F76100448735 /* MXLoginSSOFlow.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EECE62577F76100448735 /* MXLoginSSOFlow.h in Headers */ = {isa = PBXBuildFile; fileRef = B14EECE32577F76100448735 /* MXLoginSSOFlow.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EECE72577F76100448735 /* MXLoginSSOFlow.m in Sources */ = {isa = PBXBuildFile; fileRef = B14EECE42577F76100448735 /* MXLoginSSOFlow.m */; };
B14EECE82577F76100448735 /* MXLoginSSOFlow.m in Sources */ = {isa = PBXBuildFile; fileRef = B14EECE42577F76100448735 /* MXLoginSSOFlow.m */; };
B14EECEE2578FE3F00448735 /* MXAuthenticationSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B14EECED2578FE3F00448735 /* MXAuthenticationSessionTests.swift */; };
B14EECEF2578FE3F00448735 /* MXAuthenticationSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B14EECED2578FE3F00448735 /* MXAuthenticationSessionTests.swift */; };
B14EF1CA2397E90400758AF0 /* MXOlmInboundGroupSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A1513D1DAF768D00400192 /* MXOlmInboundGroupSession.m */; };
B14EF1CB2397E90400758AF0 /* MXRoomAccountData.m in Sources */ = {isa = PBXBuildFile; fileRef = 32481A831C03572900782AD3 /* MXRoomAccountData.m */; };
B14EF1CC2397E90400758AF0 /* MXEventAnnotationChunk.m in Sources */ = {isa = PBXBuildFile; fileRef = 327E9AD52284803100A98BC1 /* MXEventAnnotationChunk.m */; };
Expand Down Expand Up @@ -1763,6 +1773,11 @@
B14766B523D9D9410091F721 /* MXUsersTrustLevelSummary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXUsersTrustLevelSummary.h; sourceTree = "<group>"; };
B14766B623D9D9410091F721 /* MXUsersTrustLevelSummary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXUsersTrustLevelSummary.m; sourceTree = "<group>"; };
B14B17682464419E00C2751E /* MatrixSDK.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = MatrixSDK.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
B14EECD52577DE7A00448735 /* MXLoginSSOIdentityProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXLoginSSOIdentityProvider.h; sourceTree = "<group>"; };
B14EECD62577DE7A00448735 /* MXLoginSSOIdentityProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXLoginSSOIdentityProvider.m; sourceTree = "<group>"; };
B14EECE32577F76100448735 /* MXLoginSSOFlow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXLoginSSOFlow.h; sourceTree = "<group>"; };
B14EECE42577F76100448735 /* MXLoginSSOFlow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXLoginSSOFlow.m; sourceTree = "<group>"; };
B14EECED2578FE3F00448735 /* MXAuthenticationSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXAuthenticationSessionTests.swift; sourceTree = "<group>"; };
B14EF36B2397E90400758AF0 /* MatrixSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MatrixSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B17285782100C88A0052C51E /* MXSendReplyEventStringsLocalizable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MXSendReplyEventStringsLocalizable.h; path = ../MXSendReplyEventStringsLocalizable.h; sourceTree = "<group>"; };
B172857A2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MXSendReplyEventDefaultStringLocalizations.h; path = ../MXSendReplyEventDefaultStringLocalizations.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2540,6 +2555,7 @@
327E9AB9228451E500A98BC1 /* Event */,
32999DDC22DCD139004FF987 /* Push */,
B182B08423167A1C0057972E /* IdentityServer */,
B14EECD42577DE4400448735 /* Login */,
3281E8B319E42DFE00976E1A /* MXJSONModel.h */,
3281E8B419E42DFE00976E1A /* MXJSONModel.m */,
3281E8B519E42DFE00976E1A /* MXJSONModels.h */,
Expand Down Expand Up @@ -2878,6 +2894,7 @@
32CEEF3C23AD134A0039BA98 /* MXCrossSigningTests.m */,
ECAE7AEB24ED75F1002FA813 /* HTTPAdditionalHeadersTests.m */,
3AE97790256FC190003883EF /* MXAesTests.m */,
B14EECED2578FE3F00448735 /* MXAuthenticationSessionTests.swift */,
);
path = MatrixSDKTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3176,6 +3193,17 @@
path = Event;
sourceTree = "<group>";
};
B14EECD42577DE4400448735 /* Login */ = {
isa = PBXGroup;
children = (
B14EECD52577DE7A00448735 /* MXLoginSSOIdentityProvider.h */,
B14EECD62577DE7A00448735 /* MXLoginSSOIdentityProvider.m */,
B14EECE32577F76100448735 /* MXLoginSSOFlow.h */,
B14EECE42577F76100448735 /* MXLoginSSOFlow.m */,
);
path = Login;
sourceTree = "<group>";
};
B182B08423167A1C0057972E /* IdentityServer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3295,6 +3323,7 @@
B146D4EF21A5AF7F00D8C2C6 /* MXRealmEventScan.h in Headers */,
B146D49C21A5A04300D8C2C6 /* MXMediaScanStoreDelegate.h in Headers */,
32322A4B1E575F65005DD155 /* MXAllowedCertificates.h in Headers */,
B14EECD72577DE7A00448735 /* MXLoginSSOIdentityProvider.h in Headers */,
3213301D228B190F0070BA9B /* MXRealmAggregationsMapper.h in Headers */,
32A1515B1DB525DA00400192 /* NSObject+sortedKeys.h in Headers */,
329D3E621E251027002E2F1E /* MXRoomSummaryUpdater.h in Headers */,
Expand All @@ -3314,6 +3343,7 @@
323547D52226D3F500F15F94 /* MXWellKnown.h in Headers */,
32FFB4F0217E146A00C96002 /* MXRecoveryKey.h in Headers */,
32AF928A240EA3880008A0FD /* MXSecretShareSend.h in Headers */,
B14EECE52577F76100448735 /* MXLoginSSOFlow.h in Headers */,
B1798D0624091A0100308A8F /* MXBase64Tools.h in Headers */,
32133015228AF4EF0070BA9B /* MXRealmAggregationsStore.h in Headers */,
32CE6FB81A409B1F00317F1E /* MXFileStoreMetaData.h in Headers */,
Expand Down Expand Up @@ -3580,6 +3610,7 @@
B14EF2A32397E90400758AF0 /* MXRoomSummary.h in Headers */,
B14EF2A42397E90400758AF0 /* MXRoomCreateContent.h in Headers */,
B14EF2A52397E90400758AF0 /* MXAggregatedEditsUpdater.h in Headers */,
B14EECE62577F76100448735 /* MXLoginSSOFlow.h in Headers */,
327C3E4C23A39D91006183D1 /* MXAggregatedReferencesUpdater.h in Headers */,
B14EF2A62397E90400758AF0 /* MXAggregations.h in Headers */,
B14EF2A72397E90400758AF0 /* MXPushRuleConditionChecker.h in Headers */,
Expand Down Expand Up @@ -3685,6 +3716,7 @@
B14EF2F32397E90400758AF0 /* MXRealmMediaScanMapper.h in Headers */,
B14EF2F42397E90400758AF0 /* NSData+MatrixSDK.h in Headers */,
B14EF2F52397E90400758AF0 /* MXSDKOptions.h in Headers */,
B14EECD82577DE7A00448735 /* MXLoginSSOIdentityProvider.h in Headers */,
B14EF2F62397E90400758AF0 /* MXJSONModels.h in Headers */,
B14EF2F72397E90400758AF0 /* MXRoomEventFilter.h in Headers */,
B14EF2F82397E90400758AF0 /* MXUIKitBackgroundModeHandler.h in Headers */,
Expand Down Expand Up @@ -4091,6 +4123,7 @@
buildActionMask = 2147483647;
files = (
32A1513F1DAF768D00400192 /* MXOlmInboundGroupSession.m in Sources */,
B14EECE72577F76100448735 /* MXLoginSSOFlow.m in Sources */,
32481A851C03572900782AD3 /* MXRoomAccountData.m in Sources */,
327E9AD92284803100A98BC1 /* MXEventAnnotationChunk.m in Sources */,
327A5F56239805F600ED6329 /* MXKeyVerificationCancel.m in Sources */,
Expand Down Expand Up @@ -4305,6 +4338,7 @@
321CFDE722525A49004D31DF /* MXSASTransaction.m in Sources */,
32720D9D222EAA6F0086FFF5 /* MXDiscoveredClientConfig.m in Sources */,
B146D4F321A5AF7F00D8C2C6 /* MXRealmEventScan.m in Sources */,
B14EECD92577DE7A00448735 /* MXLoginSSOIdentityProvider.m in Sources */,
322691371E5EFF8700966A6E /* MXDeviceListOperationsPool.m in Sources */,
C6F935801E5B3ACA00FC34BF /* MXResponse.swift in Sources */,
32BA86B02152A79E008F277E /* MXRoomNameDefaultStringLocalizations.m in Sources */,
Expand Down Expand Up @@ -4360,6 +4394,7 @@
3AE97791256FC190003883EF /* MXAesTests.m in Sources */,
B146D4FE21A5C0BD00D8C2C6 /* MXEventScanStoreTests.m in Sources */,
32684CB821085F770046D2F9 /* MXLazyLoadingTests.m in Sources */,
B14EECEE2578FE3F00448735 /* MXAuthenticationSessionTests.swift in Sources */,
32832B5D1BCC048300241108 /* MXStoreMemoryStoreTests.m in Sources */,
32114A7F1A24E15500FF2EC4 /* MXMyUserTests.m in Sources */,
32832B5E1BCC048300241108 /* MXStoreNoStoreTests.m in Sources */,
Expand Down Expand Up @@ -4489,6 +4524,7 @@
B14EF2022397E90400758AF0 /* MXEventUnsignedData.m in Sources */,
324AAC792399140D00380A66 /* MXKeyVerificationKey.m in Sources */,
B14EF2032397E90400758AF0 /* MXMegolmEncryption.m in Sources */,
B14EECDA2577DE7B00448735 /* MXLoginSSOIdentityProvider.m in Sources */,
B14EF2042397E90400758AF0 /* MXIncomingRoomKeyRequest.m in Sources */,
32581DEB23C8C0C900832EAA /* MXUserTrustLevel.m in Sources */,
B14EF2052397E90400758AF0 /* MX3PidAddManager.swift in Sources */,
Expand Down Expand Up @@ -4567,6 +4603,7 @@
B14EF2432397E90400758AF0 /* MXIncomingSASTransaction.m in Sources */,
B14EF2442397E90400758AF0 /* NSObject+sortedKeys.m in Sources */,
B14EF2452397E90400758AF0 /* MXAggregatedReactionsUpdater.m in Sources */,
B14EECE82577F76100448735 /* MXLoginSSOFlow.m in Sources */,
B14EF2462397E90400758AF0 /* MXRoomMembers.m in Sources */,
32AF927E240EA0190008A0FD /* MXSecretShareManager.m in Sources */,
B14EF2472397E90400758AF0 /* MXContentScanEncryptedBody.m in Sources */,
Expand Down Expand Up @@ -4718,6 +4755,7 @@
B1E09A3A2397FD820057C069 /* MXStoreTests.m in Sources */,
B1E09A342397FD750057C069 /* MXRoomStateDynamicTests.m in Sources */,
B1E09A272397FD010057C069 /* MXMockCallStack.m in Sources */,
B14EECEF2578FE3F00448735 /* MXAuthenticationSessionTests.swift in Sources */,
B1E09A432397FD820057C069 /* MXMegolmExportEncryptionTest.m in Sources */,
32B0E3E823A3864C0054FF1A /* MXEventReferenceTests.swift in Sources */,
B1E09A402397FD820057C069 /* MXVoIPTests.m in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions MatrixSDK/JSONModels/Login/MXLoginSSOFlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright 2020 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"
#import "MXLoginSSOIdentityProvider.h"

NS_ASSUME_NONNULL_BEGIN

extern NSString *const MXLoginSSOFlowIdentityProvidersKey;

/**
`MXLoginSSOFlow` represents a SSO login or a register flow supported by the home server (See MSC2858 https://github.com/matrix-org/matrix-doc/pull/2858).
*/
@interface MXLoginSSOFlow : MXLoginFlow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very comfortable with the existence of this class and deciding that a flow is SSO or not by class check. Why don't we reuse MXLoginFlow for that? And maybe a method like -(BOOL) isSSo, which checks the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the same as Web implementation only expose relevant properties for dedicated flow. It's not a really good idea either to expose a lot of properties that can be nil or not and used in only one case.
In MXLoginSSOFlow case we expose the identity providers list can't be nil. And you know that is useful only in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's continue as is then. thanks for the explanation.


/**
List of all SSO Identity Providers supported
*/
@property (nonatomic, readonly) NSArray<MXLoginSSOIdentityProvider*> *identityProviders;

@end

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

NSString *const MXLoginSSOFlowIdentityProvidersKey = @"identity_providers";

@interface MXLoginSSOFlow()

@property (nonatomic, readwrite) NSArray<MXLoginSSOIdentityProvider*> *identityProviders;

@end

@implementation MXLoginSSOFlow

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXLoginSSOFlow *loginFlow = [MXLoginSSOFlow new];
if (loginFlow)
{
MXJSONModelSetString(loginFlow.type, JSONDictionary[@"type"]);
MXJSONModelSetArray(loginFlow.stages, JSONDictionary[@"stages"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we delegate this parsing to the superclass? I mean with another method like parseJSON: in MXLoginfFlow. My concern is that If another property added to MXLoginFlow, we'll have to maintain this one also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes he have an architecture problem. Here the class method is not really convenient. Member method like other libs would help to make calls to super implementation.
In MXLoginSSOFlow Now we can do something like:

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

And in MXLoginFlow we should have:

+ (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
{
    MXLoginSSOFlow *loginFlow = [self new];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this seems better.


NSArray *jsonIdentityProdivers;

MXJSONModelSetArray(jsonIdentityProdivers, JSONDictionary[MXLoginSSOFlowIdentityProvidersKey]);

NSArray<MXLoginSSOIdentityProvider*> *identityProviders;

if (jsonIdentityProdivers)
{
identityProviders = [MXLoginSSOIdentityProvider modelsFromJSON:jsonIdentityProdivers];
}

if (!identityProviders)
{
identityProviders = [NSArray new];
}

loginFlow.identityProviders = identityProviders;

}

return loginFlow;
}

@end
44 changes: 44 additions & 0 deletions MatrixSDK/JSONModels/Login/MXLoginSSOIdentityProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2020 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 "MXJSONModel.h"

NS_ASSUME_NONNULL_BEGIN

/**
`MXLoginSSOIdentityProvider` represents a SSO Identity Provider as described in MSC2858 (See https://github.com/matrix-org/matrix-doc/pull/2858)
*/
@interface MXLoginSSOIdentityProvider : MXJSONModel

/**
The identifier field (id field in JSON) is the Identity Provider identifier used for the SSO Web page redirection `/login/sso/redirect/{idp_id}`.
*/
@property (nonatomic, readonly) NSString *identifier;

/**
The name field is a human readable string intended to be printed by the client.
*/
@property (nonatomic, readonly) NSString *name;

/**
The icon field is an optional field that points to an icon representing the identity provider. If present then it must be an HTTPS URL to an image resource.
*/
@property (nonatomic, readonly, nullable) NSString *icon;

@end

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

@interface MXLoginSSOIdentityProvider()

@property (nonatomic, readwrite) NSString *identifier;
@property (nonatomic, readwrite) NSString *name;
@property (nonatomic, readwrite, nullable) NSString *icon;

@end

@implementation MXLoginSSOIdentityProvider

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
NSString *identifier;
NSString *name;

MXJSONModelSetString(identifier, JSONDictionary[@"id"]);
MXJSONModelSetString(name, JSONDictionary[@"name"]);

MXLoginSSOIdentityProvider *identityProvider = [MXLoginSSOIdentityProvider new];

if (identityProvider && identifier && name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have two concerns.

  1. We're declaring that identifier and name will be non-nil with NS_ASSUME_NONNULL_BEGIN, but if they are nil after parsing, we still return them nil here.
  2. This introduces some logic in a model class, which doesn't seem to be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I should return nil in this case. In the MSC identifier && name have to be non optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks.

{
identityProvider.identifier = identifier;
identityProvider.name = name;
MXJSONModelSetString(identityProvider.icon, JSONDictionary[@"icon"]);
}

return identityProvider;
}

@end
Loading