Skip to content

Commit

Permalink
Merge pull request #313 from mohssenfathi/native-prompt
Browse files Browse the repository at this point in the history
Prompt parameter for native auth
  • Loading branch information
mohssenfathi authored Aug 27, 2024
2 parents c4e92d6 + f950fc9 commit af5fd62
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 af5fd62

Please sign in to comment.