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

MXCredentials: Expose additional server login response data #1018

Merged
merged 3 commits into from
Feb 12, 2021
Merged
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes to be released in next version
*

🙌 Improvements
*
* MXCredentials: Expose additional server login response data (vector-im/element-ios/issues/4024).

🐛 Bugfix
*
Expand Down
5 changes: 5 additions & 0 deletions MatrixSDK/Data/MXCredentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, nullable) NSData *ignoredCertificate;

/**
Additonal data received during login process
*/
@property (nonatomic, nullable) NSDictionary *loginOthers;


/**
Simple MXCredentials construtor
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/Data/MXCredentials.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (instancetype)initWithLoginResponse:(MXLoginResponse*)loginResponse
_userId = loginResponse.userId;
_accessToken = loginResponse.accessToken;
_deviceId = loginResponse.deviceId;
_loginOthers = loginResponse.others;

// Use wellknown data first
_homeServer = loginResponse.wellknown.homeServer.baseUrl;
Expand Down
14 changes: 14 additions & 0 deletions MatrixSDK/JSONModels/MXJSONModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary

@end

@interface MXLoginResponse()

@property(nonatomic) NSDictionary *others;

@end

@implementation MXLoginResponse

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
Expand All @@ -199,6 +205,14 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary
MXJSONModelSetString(loginResponse.accessToken, JSONDictionary[@"access_token"]);
MXJSONModelSetString(loginResponse.deviceId, JSONDictionary[@"device_id"]);
MXJSONModelSetMXJSONModel(loginResponse.wellknown, MXWellKnown, JSONDictionary[@"well_known"]);

// populating others dictionary
NSMutableDictionary *others = [NSMutableDictionary dictionaryWithDictionary:JSONDictionary];
[others removeObjectsForKeys:@[@"home_server", @"user_id", @"access_token", @"device_id", @"well_known"]];
if (others.count)
{
loginResponse.others = others;
}
}

return loginResponse;
Expand Down