Skip to content

Commit

Permalink
Merge branch '2.x' into par
Browse files Browse the repository at this point in the history
  • Loading branch information
mohssenfathi authored Mar 29, 2024
2 parents b117951 + b1a8832 commit 120892b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 140 deletions.
104 changes: 54 additions & 50 deletions Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,45 +213,16 @@ public final class AuthorizationCodeAuthProvider: AuthProviding {

var nativeLaunched = false

func launch(app: UberApp, completion: ((Bool) -> Void)?) {
guard configurationProvider.isInstalled(
app: app,
defaultIfUnregistered: true
) else {
completion?(false)
return
}

let request = AuthorizeRequest(
app: app,
clientID: clientID,
codeChallenge: pkce.codeChallenge,
redirectURI: redirectURI,
requestURI: requestURI
)

guard let url = request.url(baseUrl: Constants.baseUrl) else {
completion?(false)
return
}

applicationLauncher.open(
url,
options: [:],
completionHandler: { opened in
if opened { nativeLaunched = true }
completion?(opened)
}
)
}

// Executes the asynchronous operation `launch` serially for each app in appPriority
// Stops the execution after the first app is successfully launched
AsyncDispatcher.exec(
for: appPriority,
for: appPriority.map { ($0, requestURI) },
with: { _ in },
asyncMethod: launch(app:completion:),
continue: { !$0 }, // Do not continue if app launched
asyncMethod: launch(context:completion:),
continue: { launched in
if launched { nativeLaunched = true }
return !launched // Continue only if app was not launched
},
finally: { [weak self] in
guard !nativeLaunched else {
return
Expand All @@ -266,30 +237,63 @@ public final class AuthorizationCodeAuthProvider: AuthProviding {
)
}

private func executePar(prefill: Prefill?,
completion: @escaping (_ requestURI: String?) -> Void) {
guard let prefill else {
completion(nil)
private func launch(context: (app: UberApp, requestURI: String?),
completion: ((Bool) -> Void)?) {
let (app, requestURI) = context
guard configurationProvider.isInstalled(
app: app,
defaultIfUnregistered: true
) else {
completion?(false)
return
}

let request = ParRequest(
let request = AuthorizeRequest(
app: app,
clientID: clientID,
prefill: prefill.dictValue
codeChallenge: pkce.codeChallenge,
redirectURI: redirectURI,
requestURI: requestURI
)

networkProvider.execute(
request: request,
completion: { result in
switch result {
case .success(let response):
completion(response.requestURI)
case .failure:
completion(nil)
}
guard let url = request.url(baseUrl: Constants.baseUrl) else {
completion?(false)
return
}

applicationLauncher.open(
url,
options: [:],
completionHandler: { opened in
completion?(opened)
}
)
}

private func executePar(prefill: Prefill?,
completion: @escaping (_ requestURI: String?) -> Void) {
guard let prefill else {
completion(nil)
return
}

let request = ParRequest(
clientID: clientID,
prefill: prefill.dictValue
)

networkProvider.execute(
request: request,
completion: { result in
switch result {
case .success(let response):
completion(response.requestURI)
case .failure:
completion(nil)
}
}
)
}

// MARK: Constants

Expand Down
4 changes: 0 additions & 4 deletions examples/UberSDK/UberSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
B28217C82B97A2E400EE786D /* AuthManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28217C72B97A2E400EE786D /* AuthManagerTests.swift */; };
B28A41712BACA97000F727C7 /* AuthorizationCodeResponseParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28A41702BACA97000F727C7 /* AuthorizationCodeResponseParserTests.swift */; };
B28A41732BAE098D00F727C7 /* AsyncDispatcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28A41722BAE098D00F727C7 /* AsyncDispatcherTests.swift */; };
B28A41752BAE331300F727C7 /* ParRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28A41742BAE331300F727C7 /* ParRequestTests.swift */; };
B28CDD322BA403A900EB1BBD /* AuthorizationCodeAuthProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28CDD312BA403A900EB1BBD /* AuthorizationCodeAuthProviderTests.swift */; };
B28CDD342BA4BE2100EB1BBD /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28CDD332BA4BE2100EB1BBD /* RequestTests.swift */; };
Expand Down Expand Up @@ -50,7 +49,6 @@
/* Begin PBXFileReference section */
B28217C72B97A2E400EE786D /* AuthManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthManagerTests.swift; sourceTree = "<group>"; };
B28A41702BACA97000F727C7 /* AuthorizationCodeResponseParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationCodeResponseParserTests.swift; sourceTree = "<group>"; };
B28A41722BAE098D00F727C7 /* AsyncDispatcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncDispatcherTests.swift; sourceTree = "<group>"; };
B28A41742BAE331300F727C7 /* ParRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParRequestTests.swift; sourceTree = "<group>"; };
B28CDD312BA403A900EB1BBD /* AuthorizationCodeAuthProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationCodeAuthProviderTests.swift; sourceTree = "<group>"; };
B28CDD332BA4BE2100EB1BBD /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,7 +106,6 @@
B28CDD352BA4C6CA00EB1BBD /* AuthorizeRequestTests.swift */,
B28A41742BAE331300F727C7 /* ParRequestTests.swift */,
B28A41702BACA97000F727C7 /* AuthorizationCodeResponseParserTests.swift */,
B28A41722BAE098D00F727C7 /* AsyncDispatcherTests.swift */,
B28CDD332BA4BE2100EB1BBD /* RequestTests.swift */,
B2D096942B97C4A00093B510 /* UberAuthErrorTests.swift */,
);
Expand Down Expand Up @@ -340,7 +337,6 @@
B28CDD362BA4C6CA00EB1BBD /* AuthorizeRequestTests.swift in Sources */,
B2D096932B97B8E70093B510 /* UberAuthMocks.swift in Sources */,
B28A41752BAE331300F727C7 /* ParRequestTests.swift in Sources */,
B28A41732BAE098D00F727C7 /* AsyncDispatcherTests.swift in Sources */,
B28CDD322BA403A900EB1BBD /* AuthorizationCodeAuthProviderTests.swift in Sources */,
B28A41712BACA97000F727C7 /* AuthorizationCodeResponseParserTests.swift in Sources */,
);
Expand Down
1 change: 0 additions & 1 deletion examples/UberSDK/UberSDK/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ final class Content {
completion: { result in
switch result {
case .success(let client):
print(client)
self.response = "\(client)"
case .failure(let error):
self.response = error.localizedDescription
Expand Down
85 changes: 0 additions & 85 deletions examples/UberSDK/UberSDKTests/UberAuth/AsyncDispatcherTests.swift

This file was deleted.

0 comments on commit 120892b

Please sign in to comment.