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

feat: self-bundle is a permitted resume callback #838

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion Auth0/LoginTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class LoginTransaction: NSObject, AuthTransaction {
}

private func handleURL(_ url: URL) -> Bool {
guard url.absoluteString.lowercased().hasPrefix(self.redirectURL.absoluteString.lowercased()),
let isMatchingURL = url.absoluteString.lowercased().hasPrefix(self.redirectURL.absoluteString.lowercased())
let isMatchingBundleID = url.scheme == Bundle.main.bundleIdentifier?.appending(".auth0")

guard isMatchingURL || isMatchingBundleID,

let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
case let items = self.handler.values(fromComponents: components),
has(state: self.state, inItems: items) else {
Expand Down
21 changes: 18 additions & 3 deletions Auth0Tests/LoginTransactionSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ class LoginTransactionSpec: QuickSpec {

override func spec() {
var transaction: LoginTransaction!
let userAgent = SpyUserAgent()
let handler = SpyGrant()
let loggerOutput = SpyOutput()
var userAgent: SpyUserAgent!
var handler: SpyGrant!
var loggerOutput: SpyOutput!
let code = "123456"

beforeEach {
userAgent = SpyUserAgent()
handler = SpyGrant()
loggerOutput = SpyOutput()
Comment on lines +17 to +19
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: reset mocks between test


transaction = LoginTransaction(redirectURL: URL(string: "https://samples.auth0.com/callback")!,
state: "state",
userAgent: userAgent,
Expand Down Expand Up @@ -50,6 +54,17 @@ class LoginTransactionSpec: QuickSpec {
expect(transaction.userAgent).to(beNil())
}

it("should succeed when using bundle schema") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: roughly identical in implementation to "can handle"

// NOTE: Interpolated so other schemes can run this test
let bundleId = Bundle.main.bundleIdentifier ?? ""
let url = URL(string: "\(bundleId).auth0://samples.auth0.com/callback?code=\(code)&state=state")!
let items = ["code": code, "state": "state"]
expect(transaction.resume(url)) == true
expect(handler.items) == items
expect(loggerOutput.messages.first).to(contain([url.absoluteString, "Callback URL"]))
expect(transaction.userAgent).to(beNil())
}

it("should fail to handle url without state") {
let url = URL(string: "https://samples.auth0.com/callback?code=\(code)")!
let expectedError = WebAuthError(code: .unknown("Invalid callback URL: \(url.absoluteString)"))
Expand Down