Skip to content

Commit

Permalink
MXRestClient: Improve registration parameters handling.
Browse files Browse the repository at this point in the history
The device display name is now provided by the Riot application.

Related to `Device name leaks personal information` element-hq/element-ios#910
  • Loading branch information
giomfo committed Oct 2, 2017
1 parent f4257b8 commit 768e7a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 11 additions & 1 deletion MatrixSDK/MXRestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ typedef enum : NSUInteger
At the end of the registration process, the SDK user should be able to construct a MXCredentials object
from the response of the last registration action request.
@note The caller may provide the device display name by adding @"initial_device_display_name" key
in the `parameters` dictionary. If the caller does not provide it, the device display name field
is filled with the device name.
@param parameters the parameters required for the current registration stage
@param success A block object called when the operation succeeds. It provides the raw JSON response
Expand Down Expand Up @@ -284,7 +288,11 @@ typedef enum : NSUInteger
@see the register method for explanation of flows that require to make several request to the
home server.
@note The caller may provide the device display name by adding @"initial_device_display_name" key
in the `parameters` dictionary. If the caller does not provide it, the device display name field
is filled with the device name.
@param parameters the parameters required for the current login stage
@param success A block object called when the operation succeeds. It provides the raw JSON response
from the server.
Expand All @@ -300,6 +308,8 @@ typedef enum : NSUInteger
Log a user in.
This method manages the full flow for simple login types and returns the credentials of the logged matrix user.
@note The device display name field is filled with the device name by default.
@param loginType the login type. Only kMXLoginFlowTypePassword (m.login.password) is supported.
@param username the user id (ex: "@bob:matrix.org") or the user id localpart (ex: "bob") of the user to register.
Expand Down
25 changes: 19 additions & 6 deletions MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -796,23 +796,36 @@ - (MXHTTPOperation*)registerOrLogin:(MXAuthAction)authAction parameters:(NSDicti
{
// If the caller does not provide it, fill the device display name field with the device name
// Do it only if parameters contains the password field, do make homeserver happy.
if (parameters[@"password"] && !parameters[@"initial_device_display_name"])
if (parameters[@"password"])
{
NSMutableDictionary *newParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
NSMutableDictionary *newParameters;

if (!parameters[@"initial_device_display_name"])
{
newParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];

#if TARGET_OS_IPHONE
NSString *deviceName = [UIDevice currentDevice].name;
NSString *deviceName = [UIDevice currentDevice].name;
#elif TARGET_OS_OSX
NSString *deviceName = [NSHost currentHost].localizedName;
NSString *deviceName = [NSHost currentHost].localizedName;
#endif
newParameters[@"initial_device_display_name"] = deviceName;
newParameters[@"initial_device_display_name"] = deviceName;
}

if (MXAuthActionRegister == authAction)
{
// Patch: Add the temporary `x_show_msisdn` flag to not filter the msisdn login type in the supported authentication flows.
if (!newParameters)
{
newParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
}
newParameters[@"x_show_msisdn"] = @(YES);
}

parameters = newParameters;
if (newParameters)
{
parameters = newParameters;
}
}

return [httpClient requestWithMethod:@"POST"
Expand Down

0 comments on commit 768e7a9

Please sign in to comment.