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

Support for HTTP Digest Authentication #742

Closed
howlingblast opened this issue Aug 1, 2017 · 2 comments
Closed

Support for HTTP Digest Authentication #742

howlingblast opened this issue Aug 1, 2017 · 2 comments

Comments

@howlingblast
Copy link
Contributor

Hi there,

Our image asset backend is protected by HTTP Digest Auth. We followed the instructions here and did implement and set our AuthenticationChallengeResponsable to handle authentication, but that didn't work. It was called and all, but HTTP Digest wasn't handled correctly.

I digged deeper into Apple documentation to understand what was happening and realised that HTTP Digest Auth was not handled in URLSessionDelegate.urlSession(_ session:, didReceive, completionHandler:) but in URLSessionTaskDelegate.urlSession(_ session:, task:, didReceive:, completionHandler:).

Our (temporary) solution was to add the correct callback to ImageDownloaderSessionHandler:

class ImageDownloaderSessionHandler {
    ...
    
    /**
    This method is exposed since the compiler requests. Do not call it.
    */
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        guard let downloader = downloadHolder else {
            return
        }
        
        downloader.authenticationChallengeResponder?.downloader(downloader, didReceive: challenge, completionHandler: completionHandler)
    }
    
    /// This will handle HTTP Basic/Digest authentication challenges
    func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        guard let downloader = downloadHolder else {
            return
        }
        
        downloader.authenticationChallengeResponder?.downloader(downloader, didReceive: challenge, completionHandler: completionHandler)
    }
  
    ...
}

Do you feel that this is the correct fix? If yes, we can provide a pull request.

@onevcat
Copy link
Owner

onevcat commented Aug 1, 2017

@reversepanda

Hi, yes. I believe it should be a correct way to fix it and I am glad to receive a pull request on this. Thank you!

And instead of reusing the current AuthenticationChallengeResponsable's downloader(_:didReceive :completionHandler:), I prefer to add a new protocol method with task contained as its parameter, to make it a forward of the original method.

@onevcat
Copy link
Owner

onevcat commented Aug 16, 2017

Released in 3.11.0.

@onevcat onevcat closed this as completed Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants