From f950fc9a3ed59f487cb1e451c4ab5d1370af1a13 Mon Sep 17 00:00:00 2001 From: mohssenfathi Date: Mon, 26 Aug 2024 14:52:22 -0700 Subject: [PATCH] Enable prompt parameter for native auth --- .../AuthorizationCodeAuthProvider.swift | 5 ++ .../AuthorizationCodeAuthProviderTests.swift | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift b/Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift index 08be719..913dab4 100644 --- a/Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift +++ b/Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift @@ -284,10 +284,15 @@ public final class AuthorizationCodeAuthProvider: AuthProviding { return } + // .login not supported for native auth + var prompt = prompt + prompt?.remove(.login) + let request = AuthorizeRequest( app: app, clientID: clientID, codeChallenge: shouldExchangeAuthCode ? pkce.codeChallenge : nil, + prompt: prompt, redirectURI: redirectURI, requestURI: requestURI, scopes: scopes diff --git a/examples/UberSDK/UberSDKTests/UberAuth/AuthorizationCodeAuthProviderTests.swift b/examples/UberSDK/UberSDKTests/UberAuth/AuthorizationCodeAuthProviderTests.swift index be72cc1..703cf07 100644 --- a/examples/UberSDK/UberSDKTests/UberAuth/AuthorizationCodeAuthProviderTests.swift +++ b/examples/UberSDK/UberSDKTests/UberAuth/AuthorizationCodeAuthProviderTests.swift @@ -123,6 +123,74 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase { XCTAssertTrue(hasCalledAuthenticationSessionBuilder) } + + func test_executeNativeLogin_prompt_includedInAuthorizeRequest() { + + configurationProvider.isInstalledHandler = { _, _ in + true + } + + let expectation = XCTestExpectation() + + let prompt: Prompt = [.consent] + let promptString = prompt.stringValue.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + + let applicationLauncher = ApplicationLaunchingMock() + applicationLauncher.openHandler = { url, _, completion in + XCTAssertTrue(url.query()!.contains("prompt=\(promptString)")) + expectation.fulfill() + completion?(true) + } + + let provider = AuthorizationCodeAuthProvider( + prompt: [.consent], + shouldExchangeAuthCode: false, + configurationProvider: configurationProvider, + applicationLauncher: applicationLauncher + ) + + + provider.execute( + authDestination: .native(), + completion: { _ in } + ) + + wait(for: [expectation], timeout: 0.2) + } + + func test_executeNativeLogin_prompt_doesNotIncluideLogin() { + + configurationProvider.isInstalledHandler = { _, _ in + true + } + + let expectation = XCTestExpectation() + + let prompt: Prompt = [.consent] + let promptString = prompt.stringValue.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + + let applicationLauncher = ApplicationLaunchingMock() + applicationLauncher.openHandler = { url, _, completion in + XCTAssertTrue(url.query()!.contains("prompt=\(promptString)")) + expectation.fulfill() + completion?(true) + } + + let provider = AuthorizationCodeAuthProvider( + prompt: [.consent, .login], + shouldExchangeAuthCode: false, + configurationProvider: configurationProvider, + applicationLauncher: applicationLauncher + ) + + + provider.execute( + authDestination: .native(), + completion: { _ in } + ) + + wait(for: [expectation], timeout: 0.2) + } func test_execute_existingSession_returnsExistingAuthSessionError() { let provider = AuthorizationCodeAuthProvider(