diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 92a7fdf..3028924 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -19,7 +19,6 @@ extension MagicBellClient { /// Application global instance of MagicBellClient static var shared = MagicBellClient( apiKey: "34ed17a8482e44c765d9e163015a8d586f0b3383", - enableHMAC: true, logLevel: .debug ) } diff --git a/README.md b/README.md index 050e803..714dbb9 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,6 @@ You can provide additional options when initializing a client: ```swift let magicbell = MagicBellClient( apiKey: "[MAGICBELL_API_KEY]" - enableHMAC: true, logLevel: .debug ) ``` @@ -125,7 +124,6 @@ let magicbell = MagicBellClient( | ------------ | ------------- | -------------------------------------------------------------------------------------------- | | `apiKey` | - | Your MagicBell's API key | | `apiSecret` | `nil` | Your MagicBell's API secret | -| `enableHMAC` | `false` | Set it to `true` if you want HMAC enabled. Note the `apiSecret` is required if set to `true` | | `logLevel` | `.none` | Set it to `.debug` to enable logs | Though the API key is meant to be published, you should not distribute the API secret. Rather, enable HMAC for your @@ -169,7 +167,7 @@ let user = magicbell.connectUser(externalId: "001") let user = magicbell.connectUser(email: "richard@example.com", externalId: "001") ``` -Each variant of `connectUser` supports an optional `hmac` parameter that is required if `enableHMAC` is enabled when initiating the `MagicBellClient`. +Each variant of `connectUser` supports an optional `hmac` parameter that should be send when HMAC Security was enabled for the project. You can connect as [many users as you need](#multi-user-support). diff --git a/Source/Common/Environment/Environment.swift b/Source/Common/Environment/Environment.swift index ad5d5e3..16da176 100644 --- a/Source/Common/Environment/Environment.swift +++ b/Source/Common/Environment/Environment.swift @@ -16,5 +16,4 @@ import Foundation struct Environment { let apiKey: String let baseUrl: URL - let isHMACEnabled: Bool } diff --git a/Source/Common/Network/HttpClient.swift b/Source/Common/Network/HttpClient.swift index 09d4a84..21d3d11 100644 --- a/Source/Common/Network/HttpClient.swift +++ b/Source/Common/Network/HttpClient.swift @@ -39,8 +39,7 @@ class DefaultHttpClient: HttpClient { urlRequest.addValue(environment.apiKey, forHTTPHeaderField: "X-MAGICBELL-API-KEY") - if environment.isHMACEnabled, - let hmac = hmac { + if let hmac = hmac { urlRequest.addValue(hmac, forHTTPHeaderField: "X-MAGICBELL-USER-HMAC") } addIdAndOrEmailHeader(externalId, email, &urlRequest) diff --git a/Source/Features/StoreRealTime/AblyConnector.swift b/Source/Features/StoreRealTime/AblyConnector.swift index cabff93..bd6bec5 100644 --- a/Source/Features/StoreRealTime/AblyConnector.swift +++ b/Source/Features/StoreRealTime/AblyConnector.swift @@ -70,7 +70,6 @@ class AblyConnector: StoreRealTime { options.authMethod = "POST" let headers = self.generateAblyHeaders( apiKey: self.environment.apiKey, - isHMACEnabled: self.environment.isHMACEnabled, externalId: self.userQuery.externalId, email: self.userQuery.email, hmac: self.userQuery.hmac @@ -97,14 +96,13 @@ class AblyConnector: StoreRealTime { private func generateAblyHeaders( apiKey: String, - isHMACEnabled: Bool, externalId: String?, email: String?, hmac: String? ) -> [String: String] { var headers = ["X-MAGICBELL-API-KEY": apiKey] - if isHMACEnabled, let hmac = hmac { + if let hmac = hmac { headers["X-MAGICBELL-USER-HMAC"] = hmac } diff --git a/Source/MagicBellClient.swift b/Source/MagicBellClient.swift index 3be1bba..efaa900 100644 --- a/Source/MagicBellClient.swift +++ b/Source/MagicBellClient.swift @@ -33,13 +33,10 @@ public class MagicBellClient { /// - Parameters: /// - apiKey: The API Key of your MagicBell project. /// - apiSecret: The API secret of your MagicBell project. Defaults to `nil`. - /// - enableHMAC: Use HMAC authentication. Defaults to `false`. If set to `true`, HMAC will be only enabled if the - /// API secret is set. /// - baseUrl: URL of the API server. Defaults to `MagicBellClient.defaultBaseUrl`. /// - logLevel: The log level, it accepts `.none` or `.debug`. Defaults to `.none`. public init( apiKey: String, - enableHMAC: Bool = false, // swiftlint:disable force_unwrapping baseUrl: URL = URL(string: "https://api.magicbell.com")!, logLevel: LogLevel = .none @@ -47,8 +44,7 @@ public class MagicBellClient { sdkProvider = DefaultSDKModule( environment: Environment( apiKey: apiKey, - baseUrl: baseUrl, - isHMACEnabled: enableHMAC + baseUrl: baseUrl ), logLevel: logLevel )