Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Ychi/example of broken basic auth #63

Closed
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
6 changes: 5 additions & 1 deletion Demo/Demo/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
}

extension SceneDelegate: TurboNavigationDelegate {}
extension SceneDelegate: TurboNavigationDelegate {
func didReceiveAuthenticationChallenge(_ challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(user: "user", password: "let-me-in", persistence: .forSession))
}
}
11 changes: 11 additions & 0 deletions Demo/Server/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
class ApplicationController < ActionController::Base
helper_method :turbo_native_app?

before_action :basic_auth

private

def basic_auth
authenticate_or_request_with_http_basic do |username, password|
username == 'username' &&
password == 'let-me-in'
end
end
end
2 changes: 2 additions & 0 deletions Sources/TurboNavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public protocol TurboNavigationDelegate: AnyObject {

/// Optional. Useful for interacting with the web view after the page loads.
func sessionDidFinishRequest(_ session: Session)
func sessionDidStartRequest(_ session: Session)
}

public extension TurboNavigationDelegate {
Expand Down Expand Up @@ -61,6 +62,7 @@ public extension TurboNavigationDelegate {
}

func sessionDidFinishRequest(_ session: Session) {}
func sessionDidStartRequest(_ session: Session) {}

func sessionDidLoadWebView(_ session: Session) {}
}
10 changes: 7 additions & 3 deletions Sources/TurboNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public class TurboNavigator {
}
}

// MARK: Internal
public let session: Session
public let modalSession: Session

let session: Session
let modalSession: Session
// MARK: Internal

// MARK: Private

Expand Down Expand Up @@ -274,4 +274,8 @@ extension TurboNavigator: SessionDelegate {
session.webView.navigationDelegate = session
delegate.sessionDidLoadWebView(session)
}

public func sessionDidStartRequest(_ session: Session) {
delegate.sessionDidStartRequest(session)
}
}