Skip to content

Commit

Permalink
Version 5.0.5. Base url path is added to the SDK config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltonalex committed Sep 1, 2022
1 parent c1cf301 commit 270ff93
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 62 deletions.
2 changes: 1 addition & 1 deletion DigiMeSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "DigiMeSDK"
s.version = "5.0.4"
s.version = "5.0.5"
s.summary = "digi.me iOS Consent Access SDK"
s.homepage = "https://github.com/digime/digime-sdk-ios"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="x7A-dh-Za3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="x7A-dh-Za3">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -253,7 +253,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="center" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="v0E-by-0I0">
<rect key="frame" x="10" y="199" width="394" height="250"/>
<rect key="frame" x="10" y="199" width="394" height="196"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BY2-4K-f0z">
<rect key="frame" x="108" y="0.0" width="178" height="34"/>
Expand All @@ -263,32 +263,24 @@
<action selector="authorizeWithService" destination="yAL-po-pNQ" eventType="touchUpInside" id="3Wy-dd-gR9"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Vvy-3n-c7k">
<rect key="frame" x="95" y="54" width="204" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<state key="normal" title="Authorize without service"/>
<connections>
<action selector="authorizeWithoutService" destination="yAL-po-pNQ" eventType="touchUpInside" id="7L2-ev-BIE"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oZS-ja-kbt">
<rect key="frame" x="149.5" y="108" width="95" height="34"/>
<rect key="frame" x="149.5" y="54" width="95" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<state key="normal" title="Add service"/>
<connections>
<action selector="addService" destination="yAL-po-pNQ" eventType="touchUpInside" id="PM3-3T-Qtk"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7ob-wc-YuE">
<rect key="frame" x="146" y="162" width="102" height="34"/>
<rect key="frame" x="146" y="108" width="102" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<state key="normal" title="Refresh data"/>
<connections>
<action selector="refreshData" destination="yAL-po-pNQ" eventType="touchUpInside" id="lKB-30-RYu"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="iY4-ep-GwY">
<rect key="frame" x="149.5" y="216" width="95" height="34"/>
<rect key="frame" x="149.5" y="162" width="95" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<state key="normal" title="Delete User">
<color key="titleColor" systemColor="systemPinkColor"/>
Expand All @@ -300,7 +292,7 @@
</subviews>
</stackView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="6aS-zW-Fvz">
<rect key="frame" x="0.0" y="469" width="414" height="393"/>
<rect key="frame" x="0.0" y="415" width="414" height="447"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<color key="textColor" systemColor="labelColor"/>
Expand Down Expand Up @@ -356,7 +348,6 @@
<connections>
<outlet property="addServiceButton" destination="oZS-ja-kbt" id="hb5-75-10d"/>
<outlet property="authWithServiceButton" destination="BY2-4K-f0z" id="lTF-xA-eOs"/>
<outlet property="authWithoutServiceButton" destination="Vvy-3n-c7k" id="DTI-DZ-oDm"/>
<outlet property="contractLabel" destination="f6q-8A-B9m" id="Ltj-Vz-2ei"/>
<outlet property="deleteUserButton" destination="iY4-ep-GwY" id="mRQ-W6-Pov"/>
<outlet property="loggerTextView" destination="6aS-zW-Fvz" id="Q9W-nc-nTW"/>
Expand Down
2 changes: 2 additions & 0 deletions Examples/DigiMeSDKExample/DigiMeSDKExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>CFBundleDisplayName</key>
<string>SDK Example</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ServiceDataViewController: UIViewController {

@IBOutlet private var contractLabel: UILabel!
@IBOutlet private var authWithServiceButton: UIButton!
@IBOutlet private var authWithoutServiceButton: UIButton!

@IBOutlet private var servicesLabel: UILabel!
@IBOutlet private var addServiceButton: UIButton!
Expand Down Expand Up @@ -67,10 +66,6 @@ class ServiceDataViewController: UIViewController {
}
}

@IBAction private func authorizeWithoutService() {
authorizeAndReadData(service: nil)
}

@IBAction private func addService() {
guard let credentials = credentialCache.credentials(for: currentContract.identifier) else {
self.logger.log(message: "Current contract must be authorized first.")
Expand Down Expand Up @@ -155,7 +150,6 @@ class ServiceDataViewController: UIViewController {
contractLabel.text = "Contract: \(currentContract.name ?? currentContract.identifier)"
if credentialCache.credentials(for: currentContract.identifier) != nil {
authWithServiceButton.isHidden = true
authWithoutServiceButton.isHidden = true
servicesLabel.isHidden = false
addServiceButton.isHidden = false
deleteUserButton.isHidden = false
Expand All @@ -177,7 +171,6 @@ class ServiceDataViewController: UIViewController {
servicesLabel.text = servicesText
}
else {
authWithoutServiceButton.isHidden = false
authWithServiceButton.isHidden = false
servicesLabel.isHidden = true
addServiceButton.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RouterTests: XCTestCase {
func testAuthorizeRequest() throws {
let jwt = UUID().uuidString
let sut = AuthorizeRoute(jwt: jwt, readOptions: options)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssert(request.httpMethod == "POST", "Error testing Authorize request. Http method is incorrect.")

Expand Down Expand Up @@ -69,7 +69,7 @@ class RouterTests: XCTestCase {
func testTokenExchangeRequest() throws {
let jwt = UUID().uuidString
let sut = TokenExchangeRoute(jwt: jwt)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "POST", "Error testing Token Exchange request. Http method is incorrect.")

Expand All @@ -88,8 +88,8 @@ class RouterTests: XCTestCase {
func testFileListRequest() throws {
let sessionKey = UUID().uuidString
let sut = FileListRoute(sessionKey: sessionKey)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "GET", "Error testing File List request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing File List request. Url is empty.")
Expand All @@ -108,8 +108,8 @@ class RouterTests: XCTestCase {
let fileId = "testFileId"
let sessionKey = UUID().uuidString
let sut = ReadDataRoute(sessionKey: sessionKey, fileId: fileId)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "GET", "Error testing File request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing File request. Url is empty.")
Expand All @@ -129,8 +129,8 @@ class RouterTests: XCTestCase {
func testTriggerRequest() throws {
let jwt = UUID().uuidString
let sut = TriggerSyncRoute(jwt: jwt, readOptions: options)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "POST", "Error testing Trigger request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing Trigger request. Url is empty.")
Expand Down Expand Up @@ -163,7 +163,7 @@ class RouterTests: XCTestCase {
let payload = Data()
let jwt = UUID().uuidString
let sut = WriteDataRoute(postboxId: postboxId, payload: payload, jwt: jwt)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "POST", "Error testing Write request. Http method is incorrect.")

Expand Down Expand Up @@ -192,8 +192,8 @@ class RouterTests: XCTestCase {
func testDeleteUserRoute() throws {
let jwt = UUID().uuidString
let sut = DeleteUserRoute(jwt: jwt)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "DELETE", "Error testing Delete User request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing Delete User request. Url is empty.")
Expand All @@ -210,8 +210,8 @@ class RouterTests: XCTestCase {

func testServicesRoute() throws {
let sut = ServicesRoute(contractId: nil)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "GET", "Error testing Services request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing Services request. Url is empty.")
Expand All @@ -228,8 +228,8 @@ class RouterTests: XCTestCase {
func testServicesRouteWithContractId() throws {
let contractId = UUID().uuidString
let sut = ServicesRoute(contractId: contractId)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "GET", "Error testing Services request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing Services request. Url is empty.")
Expand All @@ -247,8 +247,8 @@ class RouterTests: XCTestCase {
func testTokenReferenceRoute() throws {
let jwt = UUID().uuidString
let sut = TokenReferenceRoute(jwt: jwt)
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "POST", "Error testing Token Reference request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing Token Reference request. Url is empty.")
Expand All @@ -265,8 +265,8 @@ class RouterTests: XCTestCase {

func testWebKeySetRoute() throws {
let sut = WebKeySetRoute()
let request = sut.toUrlRequest()
let request = sut.toUrlRequest(with: APIConfig.baseUrlPathWithVersion)

XCTAssertEqual(request.httpMethod, "GET", "Error testing JWKS request. Http method is incorrect.")

let url = try XCTUnwrap(request.url, "Error testing JWKS request. Url is empty.")
Expand Down
8 changes: 7 additions & 1 deletion Sources/DigiMeSDK/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ public struct Configuration {
/// Use external browser to authenticate. Otherwise `SFSafariViewController` will be used.
public let authUsingExternalBrowser: Bool

/// Base URL path to override default digi.me host. If not present will use the default value.
public let baseUrl: String?

/// Creates a configuration
/// - Parameters:
/// - appId: Your application identifier
/// - contractId: Your contract identifier
/// - privateKey: Your PKCS1 private key in PEM format - either with or without the "-----BEGIN RSA PRIVATE KEY-----" header and "-----END RSA PRIVATE KEY-----" footer
public init(appId: String, contractId: String, privateKey: String, authUsingExternalBrowser: Bool = false) throws {
/// - authUsingExternalBrowser: By default will use `SFSafariViewController` instance or will forward authentication flow to the default browser on the device.
/// - baseUrl: Base URL path including version to change digi.me environment. If not present will use the default one.
public init(appId: String, contractId: String, privateKey: String, authUsingExternalBrowser: Bool = false, baseUrl: String? = nil) throws {
self.appId = appId
self.contractId = contractId
self.privateKeyData = try Crypto.base64EncodedData(from: privateKey)
self.authUsingExternalBrowser = authUsingExternalBrowser
self.baseUrl = baseUrl
}
}
7 changes: 4 additions & 3 deletions Sources/DigiMeSDK/DigiMe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class DigiMe {
public var isDownloadingFiles: Bool {
return self.downloadService.isDownloadingFiles
}

private let configuration: Configuration

private let authService: OAuthService
Expand Down Expand Up @@ -65,7 +65,7 @@ public final class DigiMe {
/// - Parameter configuration: The configuration which defines this instance
public init(configuration: Configuration) {
self.configuration = configuration
self.apiClient = APIClient()
self.apiClient = APIClient(with: configuration.baseUrl)
self.authService = OAuthService(configuration: configuration, apiClient: apiClient)
self.consentManager = ConsentManager(configuration: configuration)
self.sessionCache = SessionCache()
Expand Down Expand Up @@ -597,6 +597,7 @@ public final class DigiMe {
}

private func validateClient() -> SDKError? {
#if !DEBUG
guard let urlTypes = Bundle.main.infoDictionary?["CFBundleURLTypes"] as? [[String: Any]] else {
return SDKError.noUrlScheme
}
Expand All @@ -609,7 +610,7 @@ public final class DigiMe {
if configuration.appId == "YOUR_APP_ID" {
return SDKError.invalidAppId
}
#endif
return nil
}
}
6 changes: 4 additions & 2 deletions Sources/DigiMeSDK/Private/Authorization/ConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ final class ConsentManager: NSObject {

userConsentCompletion = completion
CallbackService.shared().setCallbackHandler(self)
var components = URLComponents(string: "\(APIConfig.baseURLPath)/apps/saas/authorize")!
let baseUrl = self.configuration.baseUrl ?? APIConfig.baseUrl
var components = URLComponents(string: "\(baseUrl)/apps/saas/authorize")!

var percentEncodedQueryItems = [
URLQueryItem(name: "code", value: preAuthCode),
Expand All @@ -68,7 +69,8 @@ final class ConsentManager: NSObject {

addServiceCompletion = completion
CallbackService.shared().setCallbackHandler(self)
var components = URLComponents(string: "\(APIConfig.baseURLPath)/apps/saas/onboard")!
let baseUrl = self.configuration.baseUrl ?? APIConfig.baseUrl
var components = URLComponents(string: "\(baseUrl)/apps/saas/onboard")!

components.percentEncodedQueryItems = [
URLQueryItem(name: "code", value: token),
Expand Down
2 changes: 1 addition & 1 deletion Sources/DigiMeSDK/Private/Cache/SessionCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class SessionCache {

/// Initializes an instance of session cache
init() {
domain = Bundle.main.bundleIdentifier ?? "me.digi.sdk.session"
domain = "me.digi.sdk.session"
keyPrefix = "\(domain)."
}

Expand Down
3 changes: 0 additions & 3 deletions Sources/DigiMeSDK/Private/Files/FileDownloadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class FileDownloadOperation: RetryingOperation {
self.retry()
newResult = nil
}
catch let sdkError as SDKError {
newResult = .failure(sdkError)
}
catch {
newResult = .failure(.fileDownloadOperationError)
}
Expand Down
Loading

0 comments on commit 270ff93

Please sign in to comment.