From 5748ae33c9e6ee5cd87dc441ab90c4081606f4f5 Mon Sep 17 00:00:00 2001 From: Igor Ferreira Date: Thu, 29 Aug 2024 15:53:17 +0200 Subject: [PATCH] Replace sample project entrypoint --- MWAppAuth/MWAppAuth.xcodeproj/project.pbxproj | 32 +- .../MWAppAuth/App Configuration/app.json | 291 ------------------ MWAppAuth/MWAppAuth/App.swift | 33 ++ MWAppAuth/MWAppAuth/SceneDelegate.swift | 4 + .../AppAuthStep/AuthStepItem.swift | 3 +- .../AppAuthStep/MWAppAuthStep.swift | 28 +- .../MWAppAuthStepViewController+AppAuth.swift | 28 +- 7 files changed, 102 insertions(+), 317 deletions(-) delete mode 100644 MWAppAuth/MWAppAuth/App Configuration/app.json create mode 100644 MWAppAuth/MWAppAuth/App.swift diff --git a/MWAppAuth/MWAppAuth.xcodeproj/project.pbxproj b/MWAppAuth/MWAppAuth.xcodeproj/project.pbxproj index f382e4e..90bd61f 100644 --- a/MWAppAuth/MWAppAuth.xcodeproj/project.pbxproj +++ b/MWAppAuth/MWAppAuth.xcodeproj/project.pbxproj @@ -11,9 +11,9 @@ 36C18373256EA08D0044A74B /* MWAppAuthPlugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36C18372256EA08D0044A74B /* MWAppAuthPlugin.framework */; }; 36C18374256EA08D0044A74B /* MWAppAuthPlugin.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36C18372256EA08D0044A74B /* MWAppAuthPlugin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 36E1C299280084B100083D41 /* MobileWorkflowAppAuthTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B6613F27AD736D00157DD2 /* MobileWorkflowAppAuthTests.swift */; }; + 78907CDA2C80AA8D00BF030B /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78907CD92C80AA8D00BF030B /* App.swift */; }; 78B6614227AD736D00157DD2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78B6613327AD736D00157DD2 /* Assets.xcassets */; }; 78B6614327AD736D00157DD2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78B6613427AD736D00157DD2 /* LaunchScreen.storyboard */; }; - 78B6614627AD736D00157DD2 /* app.json in Resources */ = {isa = PBXBuildFile; fileRef = 78B6613B27AD736D00157DD2 /* app.json */; }; 78B6614727AD736D00157DD2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B6613C27AD736D00157DD2 /* AppDelegate.swift */; }; 78B6614827AD736D00157DD2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B6613D27AD736D00157DD2 /* SceneDelegate.swift */; }; C9F2C9042DFBD1CB244DE920 /* Pods_MWAppAuth_MWAppAuth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F65C712464527886D8385CD /* Pods_MWAppAuth_MWAppAuth.framework */; }; @@ -51,12 +51,12 @@ 50E391EFCE536F205DAC6CDB /* Pods-MobileWorkflowAppAuth.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MobileWorkflowAppAuth.release.xcconfig"; path = "Target Support Files/Pods-MobileWorkflowAppAuth/Pods-MobileWorkflowAppAuth.release.xcconfig"; sourceTree = ""; }; 5262FE7CC49938EBA6CFC374 /* Pods-MobileWorkflowAppAuthTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MobileWorkflowAppAuthTests.debug.xcconfig"; path = "Target Support Files/Pods-MobileWorkflowAppAuthTests/Pods-MobileWorkflowAppAuthTests.debug.xcconfig"; sourceTree = ""; }; 53110D20025AF8643CEC84F5 /* Pods-MWAppAuth-MWAppAuth.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MWAppAuth-MWAppAuth.debug.xcconfig"; path = "Target Support Files/Pods-MWAppAuth-MWAppAuth/Pods-MWAppAuth-MWAppAuth.debug.xcconfig"; sourceTree = ""; }; + 78907CD92C80AA8D00BF030B /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; 78B6613327AD736D00157DD2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 78B6613527AD736D00157DD2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 78B6613727AD736D00157DD2 /* MobileWorkflowAppAuth.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = MobileWorkflowAppAuth.entitlements; sourceTree = ""; }; 78B6613827AD736D00157DD2 /* fw-shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "fw-shared.xcconfig"; sourceTree = ""; }; 78B6613927AD736D00157DD2 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 78B6613B27AD736D00157DD2 /* app.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = app.json; sourceTree = ""; }; 78B6613C27AD736D00157DD2 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 78B6613D27AD736D00157DD2 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 78B6613F27AD736D00157DD2 /* MobileWorkflowAppAuthTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileWorkflowAppAuthTests.swift; sourceTree = ""; }; @@ -108,9 +108,9 @@ 78B6613127AD736D00157DD2 /* MWAppAuth */ = { isa = PBXGroup; children = ( + 78907CD92C80AA8D00BF030B /* App.swift */, 78B6613227AD736D00157DD2 /* Resources */, 78B6613627AD736D00157DD2 /* Supporting Files */, - 78B6613A27AD736D00157DD2 /* App Configuration */, 78B6613C27AD736D00157DD2 /* AppDelegate.swift */, 78B6613D27AD736D00157DD2 /* SceneDelegate.swift */, ); @@ -136,14 +136,6 @@ path = "Supporting Files"; sourceTree = ""; }; - 78B6613A27AD736D00157DD2 /* App Configuration */ = { - isa = PBXGroup; - children = ( - 78B6613B27AD736D00157DD2 /* app.json */, - ); - path = "App Configuration"; - sourceTree = ""; - }; 78B6613E27AD736D00157DD2 /* MWAppAuthTests */ = { isa = PBXGroup; children = ( @@ -256,7 +248,7 @@ CreatedOnToolsVersion = 7.2; DevelopmentTeam = F94732585Z; LastSwiftMigration = 1020; - ProvisioningStyle = Manual; + ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.DataProtection = { enabled = 1; @@ -296,7 +288,6 @@ buildActionMask = 2147483647; files = ( 78B6614227AD736D00157DD2 /* Assets.xcassets in Resources */, - 78B6614627AD736D00157DD2 /* app.json in Resources */, 78B6614327AD736D00157DD2 /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -380,6 +371,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 78907CDA2C80AA8D00BF030B /* App.swift in Sources */, 78B6614727AD736D00157DD2 /* AppDelegate.swift in Sources */, 78B6614827AD736D00157DD2 /* SceneDelegate.swift in Sources */, ); @@ -523,13 +515,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "MWAppAuth/Supporting Files/MobileWorkflowAppAuth.entitlements"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = F94732585Z; INFOPLIST_FILE = "MWAppAuth/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.futureworkshops.MobileWorkflowAppAuth; + PRODUCT_BUNDLE_IDENTIFIER = com.futureworkshops.MobileWorkflow.internal; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = "MobileWorkflow Login Plugin Sample"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; }; @@ -541,13 +534,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "MWAppAuth/Supporting Files/MobileWorkflowAppAuth.entitlements"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = F94732585Z; INFOPLIST_FILE = "MWAppAuth/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.futureworkshops.MobileWorkflowAppAuth; + PRODUCT_BUNDLE_IDENTIFIER = com.futureworkshops.MobileWorkflow.internal; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = "MobileWorkflow Login Plugin Sample"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; }; diff --git a/MWAppAuth/MWAppAuth/App Configuration/app.json b/MWAppAuth/MWAppAuth/App Configuration/app.json deleted file mode 100644 index 9b60a23..0000000 --- a/MWAppAuth/MWAppAuth/App Configuration/app.json +++ /dev/null @@ -1,291 +0,0 @@ -{ - "id": 249, - "name": "Health Check", - "systemTintColor": "blue", - "navigationStyle": "list", - "gatherAnalytics": false, - "workflows": [ - { - "steps": [ - { - "optional": false, - "_class": "MobileWorkflowNetworkDisplayStep", - "identifier": "current_user", - "title": "Current User", - "url": "/users/current", - "uuid": "0dea5294-b253-46f1-b4bc-a61ccbd2bf1f", - "type": "networkDisplay" - } - ], - "navigationRules": [ - { - "from": "current_user", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 517, - "identifier": "Login - Current User", - "name": "Login - Current User", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "steps": [ - { - "optional": false, - "_class": "MobileWorkflowOAuth2Step", - "identifier": "login", - "title": "Login", - "text": "Login with Doorkeeper", - "oAuth2Url": "https://mw-health-check.herokuapp.com/oauth", - "oAuth2ClientId": "K6rCtOXPFQLa5XTL8DCqAPa24atiX5o1N6PVCpqrGA0", - "oAuth2ClientSecret": "1mMg3L1hcYvysKGXf7Cnp8W5UHdosow7Q2W1ar94zw4", - "oAuth2Scope": "public", - "oAuth2RedirectScheme": "mww", - "uuid": "16da25e8-0875-47e2-af3a-e539bc8c722b", - "type": "networkOAuth2" - } - ], - "navigationRules": [ - { - "from": "login", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 519, - "identifier": "Login - Doorkeeper", - "name": "Login - Doorkeeper", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "steps": [ - { - "optional": false, - "_class": "MobileWorkflowOAuth2Step", - "identifier": "login", - "title": "Login", - "text": "Login with Okta", - "oAuth2Url": "https://dev-379980.okta.com/oauth2/v1", - "oAuth2ClientId": "0oa5lydq53ISN9O9A357", - "oAuth2Scope": "openid", - "oAuth2RedirectScheme": "mww", - "uuid": "d36748f1-45e8-4917-b93b-3645294699fc", - "type": "networkOAuth2" - } - ], - "navigationRules": [ - { - "from": "login", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 518, - "identifier": "Login - OAuth (Okta)", - "name": "Login - OAuth (Okta)", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "steps": [ - { - "optional": false, - "_class": "MobileWorkflowDocumentCaptureStep", - "identifier": "document", - "title": "Document", - "uuid": "3b2c2cbb-2659-4822-a16b-00be3866888d", - "type": "documentCapture" - }, - { - "optional": false, - "_class": "MobileWorkflowNetworkStep", - "identifier": "uploading", - "title": "Uploading", - "url": "/documents", - "requestPropertyIdentifiers": [ - "document.pdf" - ], - "uuid": "3b055fb5-d56c-4e83-a5a7-cfcd7b9054b3", - "type": "network" - } - ], - "navigationRules": [ - { - "from": "document", - "rules": [ - { - "to": "uploading" - } - ] - }, - { - "from": "uploading", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 474, - "identifier": "Upload Document", - "name": "Upload Document", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "steps": [ - { - "optional": false, - "_class": "ORKImageCaptureStep", - "identifier": "image", - "title": "Image", - "devicePosition": 1, - "uuid": "5c70bc8a-3e27-482b-9ffa-0cdac14226b1", - "type": "imageCapture" - }, - { - "optional": false, - "_class": "MobileWorkflowNetworkStep", - "identifier": "uploading", - "title": "Uploading", - "url": "/back_images", - "requestPropertyIdentifiers": [ - "image.jpg" - ], - "uuid": "873d4fd0-fe62-4813-9023-a1e19dc820f6", - "type": "network" - } - ], - "navigationRules": [ - { - "from": "image", - "rules": [ - { - "to": "uploading" - } - ] - }, - { - "from": "uploading", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 472, - "identifier": "Upload Image (Back)", - "name": "Upload Image (Back)", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "steps": [ - { - "optional": false, - "_class": "ORKImageCaptureStep", - "identifier": "image", - "title": "Image", - "devicePosition": 2, - "uuid": "a91ee13b-83c9-4515-b862-caad86e7efcd", - "type": "imageCapture" - }, - { - "optional": false, - "_class": "MobileWorkflowNetworkStep", - "identifier": "uploading", - "title": "Uploading", - "url": "/front_images", - "requestPropertyIdentifiers": [ - "image.jpg" - ], - "uuid": "18c45f17-8027-46d1-9e17-154403eb447b", - "type": "network" - } - ], - "navigationRules": [ - { - "from": "image", - "rules": [ - { - "to": "uploading" - } - ] - }, - { - "from": "uploading", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "id": 473, - "identifier": "Upload Image (Front)", - "name": "Upload Image (Front)", - "sfSymbolName": "", - "materialIconName": "" - }, - { - "id": 964, - "identifier": "Login with Apple", - "materialIconName": "", - "name": "Login with Apple", - "navigationRules": [ - { - "from": "login", - "rules": [ - { - "to": "ORKNullStepIdentifier" - } - ] - } - ], - "sfSymbolName": "", - "steps": [ - { - "identifier": "login", - "imageURL": "https://source.unsplash.com/ObpCE_X3j6U/800x600", - "items": [ - { - "appleAccessTokenURL": "https://mw-apple-auth.herokuapp.com/appleauth", - "appleEmailScope": true, - "appleFullNameScope": true, - "id": 1, - "type": "apple" - } - ], - "optional": false, - "text": "Feel calm and secure with Apple login. Privacy matters.", - "title": "Login", - "type": "networkOAuth2", - "uuid": "e73e28c6-55a6-4547-85fa-d1742dd6d295" - } - ] - } - ], - "servers": [ - { - "id": 125, - "url": "https://mw-health-check.herokuapp.com" - } - ], - "locales": [ - - ] -} diff --git a/MWAppAuth/MWAppAuth/App.swift b/MWAppAuth/MWAppAuth/App.swift new file mode 100644 index 0000000..db93b07 --- /dev/null +++ b/MWAppAuth/MWAppAuth/App.swift @@ -0,0 +1,33 @@ +// +// App.swift +// MWAppAuth +// +// Created by Igor Ferreira on 29/8/24. +// Copyright © 2024 Future Workshops. All rights reserved. +// + +import Foundation +import MobileWorkflowCore +import MWAppAuthPlugin + +let app = AppRail( + name: "Health Check", + steps: [ + .restStack(id: "0dea5294-b253-46f1-b4bc-a61ccbd2bf1f", title: "Current User", url: "/users/current"), + .appAuthStep(id: "16da25e8-0875-47e2-af3a-e539bc8c722b", title: "Login", options: [ + .signInSignInOauthItem( + label: "Login with Doorkeeper", + oAuth2ClientId: "K6rCtOXPFQLa5XTL8DCqAPa24atiX5o1N6PVCpqrGA0", + oAuth2ClientSecret: "1mMg3L1hcYvysKGXf7Cnp8W5UHdosow7Q2W1ar94zw4", + oAuth2Scope: "public", + oAuth2RedirectScheme: "mww", + oAuth2Url: "https://mw-health-check.herokuapp.com/oauth", + oAuth2TokenUrl: "https://mw-health-check.herokuapp.com/token" + ) + ], text: "Login with Doorkeeper") + ], + navigation: .primary(mainStep: "16da25e8-0875-47e2-af3a-e539bc8c722b", authenticationStep: "16da25e8-0875-47e2-af3a-e539bc8c722b"), + servers: [ + .http(id: 125, url: "https://mw-health-check.herokuapp.com") + ] +) diff --git a/MWAppAuth/MWAppAuth/SceneDelegate.swift b/MWAppAuth/MWAppAuth/SceneDelegate.swift index 6f2df6e..fea2cbd 100644 --- a/MWAppAuth/MWAppAuth/SceneDelegate.swift +++ b/MWAppAuth/MWAppAuth/SceneDelegate.swift @@ -18,4 +18,8 @@ class SceneDelegate: MWSceneDelegate { super.scene(scene, willConnectTo: session, options: connectionOptions) } + + override func preferredConfigurations(urlContexts: Set) -> [AppConfigurationContext] { + return [.config(app, serverId: 125)] + } } diff --git a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/AuthStepItem.swift b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/AuthStepItem.swift index 341186f..158eca3 100644 --- a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/AuthStepItem.swift +++ b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/AuthStepItem.swift @@ -56,6 +56,7 @@ class AuthStepItem: Codable { struct OAuth2Config { let oAuth2Url: String + let oAuth2TokenUrl: String? let oAuth2ClientId: String let oAuth2ClientSecret: String? let oAuth2Scope: String @@ -98,7 +99,7 @@ extension AuthStepItem { guard let oAuth2ClientId = self.oAuth2ClientId else { throw ParseError.invalidStepData(cause: "Missing required 'oAuth2ClientId' parameter") } guard let oAuth2Scope = self.oAuth2Scope else { throw ParseError.invalidStepData(cause: "Missing required 'oAuth2Scope' parameter") } guard let oAuth2RedirectScheme = self.oAuth2RedirectScheme else { throw ParseError.invalidStepData(cause: "Missing required 'oAuth2RedirectScheme' parameter") } - return .oauth(buttonTitle: self.buttonTitle, config: OAuth2Config(oAuth2Url: oAuth2Url, oAuth2ClientId: oAuth2ClientId, oAuth2ClientSecret: self.oAuth2ClientSecret, oAuth2Scope: oAuth2Scope, oAuth2RedirectScheme: oAuth2RedirectScheme)) + return .oauth(buttonTitle: self.buttonTitle, config: OAuth2Config(oAuth2Url: oAuth2Url, oAuth2TokenUrl: oAuth2TokenUrl, oAuth2ClientId: oAuth2ClientId, oAuth2ClientSecret: self.oAuth2ClientSecret, oAuth2Scope: oAuth2Scope, oAuth2RedirectScheme: oAuth2RedirectScheme)) case .oauthRopc: guard let oAuth2TokenUrl = self.oAuth2TokenUrl else { throw ParseError.invalidStepData(cause: "Missing required 'oAuth2TokenUrl' parameter") } guard let oAuth2ClientId = self.oAuth2ClientId else { throw ParseError.invalidStepData(cause: "Missing required 'oAuth2ClientId' parameter") } diff --git a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStep.swift b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStep.swift index f7f5689..cf73919 100644 --- a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStep.swift +++ b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStep.swift @@ -319,9 +319,9 @@ public struct SignInSignInItem: Codable { oAuth2ClientSecret: String, oAuth2Scope: String, oAuth2RedirectScheme: String, - oAuth2TokenUrl: String, oAuth2Url: String, imageURL: String? = nil, + oAuth2TokenUrl: String? = nil, text: String? = nil ) -> SignInSignInItem { return SignInSignInItem(label: label, oAuth2ClientId: oAuth2ClientId, oAuth2ClientSecret: oAuth2ClientSecret, oAuth2Scope: oAuth2Scope, appleAccessTokenURL: nil, appleEmailScope: nil, appleFullNameScope: nil, imageURL: imageURL, oAuth2RedirectScheme: oAuth2RedirectScheme, oAuth2TokenUrl: oAuth2TokenUrl, oAuth2Url: oAuth2Url, text: text, type: AuthStepItem.ItemType.oauth.rawValue) @@ -329,8 +329,8 @@ public struct SignInSignInItem: Codable { } public class SignInSignInMetadata: StepMetadata { - enum CodingKeys: CodingKey { - case options + enum CodingKeys: String, CodingKey { + case options = "items" case imageURL case text } @@ -362,3 +362,25 @@ public class SignInSignInMetadata: StepMetadata { try super.encode(to: encoder) } } + +public extension StepMetadata { + static func appAuthStep( + id: String, + title: String, + options: [SignInSignInItem], + imageURL: String? = nil, + text: String? = nil, + next: PushLinkMetadata? = nil, + links: [LinkMetadata] = [] + ) -> SignInSignInMetadata { + SignInSignInMetadata( + id: id, + title: title, + options: options, + imageURL: imageURL, + text: text, + next: next, + links: links + ) + } +} diff --git a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStepViewController+AppAuth.swift b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStepViewController+AppAuth.swift index 9ec7459..f30762d 100644 --- a/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStepViewController+AppAuth.swift +++ b/MWAppAuthPlugin/MWAppAuthPlugin/AppAuthStep/MWAppAuthStepViewController+AppAuth.swift @@ -21,8 +21,18 @@ extension MWAppAuthStepViewController { let oAuth2Url = URL(string: oAuth2Path) else { return } - let authorizationEndpoint = oAuth2Url.appendingPathComponent(OAuthPaths.authorization) - let tokenEndpoint = oAuth2Url.appendingPathComponent(OAuthPaths.token) + let authorizationEndpoint: URL + let tokenEndpoint: URL + + if let tokenPath = config.oAuth2TokenUrl, + !tokenPath.isEmpty, + let tokenURL = URL(string: tokenPath) { + authorizationEndpoint = oAuth2Url + tokenEndpoint = tokenURL + } else { + authorizationEndpoint = oAuth2Url.appendingPathComponent(OAuthPaths.authorization) + tokenEndpoint = oAuth2Url.appendingPathComponent(OAuthPaths.token) + } self.showLoading() @@ -40,7 +50,7 @@ extension MWAppAuthStepViewController { let response = try await self.authenticate( oAuth2Url: fullValidURL, - callbackURLScheme: config.oAuth2RedirectScheme + "://callback" + callbackURLScheme: config.oAuth2RedirectScheme ) guard let code = URLComponents(url: response, resolvingAgainstBaseURL: false)? @@ -134,6 +144,7 @@ extension MWAppAuthStepViewController { return continuation.resume(throwing: URLError(.badServerResponse)) } } + session.presentationContextProvider = self session.start() } } @@ -215,6 +226,17 @@ extension MWAppAuthStepViewController { // MARK: - Authorization Controller Presentation +extension MWAppAuthStepViewController: ASWebAuthenticationPresentationContextProviding { + + func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { + guard let windows = self.view.window else { + preconditionFailure() + } + + return windows + } +} + extension MWAppAuthStepViewController: ASAuthorizationControllerPresentationContextProviding { func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {