Skip to content

Commit

Permalink
fix: Custom http headers and query parameters for ios (#28)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daniellindau committed Nov 25, 2024
1 parent dd2f630 commit a69edd5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions ios/HaapiModule/ConfigurationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ 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"),
baseURL: try getUrlOrThrow(data: data, configKey: "baseUri"),
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)
Expand Down Expand Up @@ -68,4 +72,15 @@ class ConfigurationHelper {
.split(separator: " ")
.map { String($0) }
}

private static func getStringMap(data: Dictionary<String, Any>, configKey: String) -> Dictionary<String, String> {
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
}
}

0 comments on commit a69edd5

Please sign in to comment.