From fb670289912d4234cda13aea0b551d3c700ababf Mon Sep 17 00:00:00 2001 From: Daniel Lindau Date: Mon, 25 Nov 2024 10:49:01 +0100 Subject: [PATCH] fix: Custom http headers and query parameters for ios (#28) Adding support for additional query parameters in authorization request and http headers in the authentication requests This was already supported on android. Note that the headers will only be sent in authentication requests,not in the token request. --- ios/HaapiModule/ConfigurationHelper.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ios/HaapiModule/ConfigurationHelper.swift b/ios/HaapiModule/ConfigurationHelper.swift index 4973188..bdfcb36 100644 --- a/ios/HaapiModule/ConfigurationHelper.swift +++ b/ios/HaapiModule/ConfigurationHelper.swift @@ -32,6 +32,8 @@ class ConfigurationHelper { delegate: validateTlsCertificate ? nil : TrustAllCertsDelegate(), delegateQueue: nil) let boundedTokenConfiguration = BoundedTokenConfiguration() + let extraRequestParameters = getStringMap(data: data, configKey: "extraRequestParameters") + let extraHttpHeaders = getStringMap(data: data, configKey: "extraHttpHeaders") return HaapiConfiguration(name: getStringOrDefault(data: data, configKey: "configurationName", defaultString: "HaapiModule"), clientId: try getStringOrThrow(data: data, configKey: "clientId"), @@ -39,8 +41,10 @@ class ConfigurationHelper { tokenEndpointURL: try getUrlOrThrow(data: data, configKey: "tokenEndpointUri"), authorizationEndpointURL: try getUrlOrThrow(data: data, configKey: "authorizationEndpointUri"), appRedirect: getStringOrDefault(data: data, configKey: "appRedirect", defaultString: "app:start"), - httpHeadersProvider: nil, - authorizationParametersProvider: { () -> OAuthAuthorizationParameters in OAuthAuthorizationParameters(scopes: scope, acrValues: acrValues) }, + httpHeadersProvider: { extraHttpHeaders }, + authorizationParametersProvider: { () -> OAuthAuthorizationParameters in OAuthAuthorizationParameters(scopes: scope, + acrValues: acrValues, + extraRequestParameters: extraRequestParameters) }, isAutoRedirect: true, urlSession: urlSession, tokenBoundConfiguration: boundedTokenConfiguration) @@ -68,4 +72,15 @@ class ConfigurationHelper { .split(separator: " ") .map { String($0) } } + + private static func getStringMap(data: Dictionary, configKey: String) -> Dictionary { + guard let map = data[configKey] as? [String: Any] else { return [String: String]() } + var stringMap = [String: String]() + for (key, value) in map { + if let value = value as? String { + stringMap[key] = value + } + } + return stringMap + } }