Skip to content

Commit

Permalink
Enable prompt parameter for native auth
Browse files Browse the repository at this point in the history
  • Loading branch information
mohssenfathi committed Aug 27, 2024
1 parent c4e92d6 commit f950fc9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
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

0 comments on commit f950fc9

Please sign in to comment.