Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt parameter for native auth #313

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading