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

[ECO-4711] Added deviceSecret in device registration POST. #1893

Merged
merged 3 commits into from
Mar 26, 2024
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
12 changes: 11 additions & 1 deletion Source/ARTJsonLikeEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ - (NSData *)encodeDeviceDetails:(ARTDeviceDetails *)deviceDetails error:(NSError
return [self encode:[self deviceDetailsToDictionary:deviceDetails] error:error];
}

- (NSData *)encodeLocalDevice:(ARTLocalDevice *)device error:(NSError **)error {
return [self encode:[self localDeviceToDictionary:device] error:error];
}

- (ARTDeviceDetails *)decodeDeviceDetails:(NSData *)data error:(NSError **)error {
return [self deviceDetailsFromDictionary:[self decodeDictionary:data error:nil] error:error];
}
Expand Down Expand Up @@ -627,7 +631,7 @@ - (NSDictionary *)tokenDetailsToDictionary:(ARTTokenDetails *)tokenDetails {
return dictionary;
}

- (NSDictionary *)deviceDetailsToDictionary:(ARTDeviceDetails *)deviceDetails {
- (NSMutableDictionary *)deviceDetailsToDictionary:(ARTDeviceDetails *)deviceDetails {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

dictionary[@"id"] = deviceDetails.id;
Expand All @@ -643,6 +647,12 @@ - (NSDictionary *)deviceDetailsToDictionary:(ARTDeviceDetails *)deviceDetails {
return dictionary;
}

- (NSDictionary *)localDeviceToDictionary:(ARTLocalDevice *)device {
NSMutableDictionary *dictionary = [self deviceDetailsToDictionary:device];
dictionary[@"deviceSecret"] = device.secret;
return dictionary;
}

- (ARTDeviceDetails *)deviceDetailsFromDictionary:(NSDictionary *)input error:(NSError * __autoreleasing *)error {
ARTLogVerbose(_logger, @"RS:%p ARTJsonLikeEncoder<%@>: deviceDetailsFromDictionary %@", _rest, [_delegate formatAsString], input);

Expand Down
3 changes: 2 additions & 1 deletion Source/ARTPushActivationStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error {
// Asynchronous HTTP request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"/push/deviceRegistrations"]];
request.HTTPMethod = @"POST";
request.HTTPBody = [[self->_rest defaultEncoder] encodeDeviceDetails:local error:nil];
request.HTTPBody = [[self->_rest defaultEncoder] encodeLocalDevice:local error:nil];
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

ARTLogDebug(self->_logger, @"%@: device registration with request %@", NSStringFromClass(self.class), request);
Expand Down Expand Up @@ -298,6 +298,7 @@ - (void)syncDevice {
request.HTTPMethod = @"PUT";
request.HTTPBody = [[self->_rest defaultEncoder] encodeDeviceDetails:local error:nil];
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];
[request setDeviceAuthentication:local];

ARTLogDebug(self->_logger, @"%@: sync device with request %@", NSStringFromClass(self.class), request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
Expand Down
4 changes: 4 additions & 0 deletions Source/include/Ably/ARTEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@class ARTDeviceIdentityTokenDetails;
@class ARTDevicePushDetails;
@class ARTPushChannelSubscription;
@class ARTLocalDevice;

@protocol ARTPushRecipient;

Expand Down Expand Up @@ -67,6 +68,9 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSData *)encodeDeviceDetails:(ARTDeviceDetails *)deviceDetails error:(NSError *_Nullable *_Nullable)error;
- (nullable ARTDeviceDetails *)decodeDeviceDetails:(NSData *)data error:(NSError *_Nullable *_Nullable)error;

// LocalDevice
- (nullable NSData *)encodeLocalDevice:(ARTLocalDevice *)device error:(NSError *_Nullable *_Nullable)error;

// ChannelDetails
- (nullable ARTChannelDetails *)decodeChannelDetails:(NSData *)data error:(NSError *_Nullable *_Nullable)error;

Expand Down
1 change: 1 addition & 0 deletions Test/Tests/PushActivationStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class PushActivationStateMachineTests: XCTestCase {
XCTAssertEqual(url.host, rest.internal.options.restUrl().host)
XCTAssertEqual(request.httpMethod, "POST")
XCTAssertEqual(body.value(forKey: "id") as? String, rest.device.id)
XCTAssertEqual(body.value(forKey: "deviceSecret") as? String, rest.device.secret)
XCTAssertEqual(body.value(forKey: "push") as? [String: [String: AnyHashable]], expectedPushRecipient)
XCTAssertEqual(body.value(forKey: "formFactor") as? String, expectedFormFactor)
XCTAssertEqual(body.value(forKey: "platform") as? String, expectedPlatform)
Expand Down
Loading