Skip to content

HTTP Basic Auth implementation #1569

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

Merged
merged 1 commit into from
Jul 25, 2018
Merged

Conversation

saiHemak
Copy link
Contributor

This PR is based on #1407 . I have picked up the implementation from #1407 PR and added HTTPServer changes which are required for testing this functionality.

@pushkarnk please review

@@ -192,3 +192,21 @@ open class URLAuthenticationChallenge : NSObject, NSSecureCoding {
}
}
}

extension _HTTPURLProtocol : URLAuthenticationChallengeSender {
Copy link
Member

Choose a reason for hiding this comment

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

We must add NSUnimplemented() or fatalError() with a message to these empty methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ..Thanks

@pushkarnk
Copy link
Member

@swift-ci please test

let host = response.url?.host ?? ""
let port = response.url?.port ?? 80 //we're doing http
let _protocol = response.url?.scheme
let wwwAuthHeader = response.allHeaderFields["WWW-Authenticate"] as! String
Copy link
Member

Choose a reason for hiding this comment

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

Please handle the case where the WWW-Authenticate header isn't present.

@pushkarnk pushkarnk requested a review from ianpartridge May 31, 2018 06:41
@saiHemak saiHemak force-pushed the http-server branch 5 times, most recently from 538082e to 2e67353 Compare June 1, 2018 08:31
@pushkarnk pushkarnk changed the title HTTP Basic Auth implemenatation HTTP Basic Auth implementation Jun 3, 2018
@saiHemak saiHemak force-pushed the http-server branch 2 times, most recently from bc896a6 to ec4f3ea Compare June 4, 2018 11:27
@saiHemak
Copy link
Contributor Author

saiHemak commented Jun 4, 2018

@pushkarnk As of now the code is crashing when the header "WWW-Authenticate is not present.So, we can handle this in two ways either throwing the fatalError with a message which will be no different from the earlier crash but with a proper message or invoking the urlProtocol(`protocol`, didFailWithError: delegate . I have implemented the latter way . However the error message relevant to this scenario seems to be unavailable in URLError class. I am not sure whether I can add new errors to this class . Hence I have set the error code as NSURLErrorUserAuthenticationRequired . Please let me know if this is acceptable.

@@ -580,7 +616,24 @@ extension _ProtocolClient : URLProtocolClient {
}

func urlProtocol(_ protocol: URLProtocol, didReceive challenge: URLAuthenticationChallenge) {
NSUnimplemented()
guard let task = `protocol`.task else { fatalError() }
Copy link
Member

Choose a reason for hiding this comment

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

Please call fatalError() with a clear error message.

@@ -580,7 +616,24 @@ extension _ProtocolClient : URLProtocolClient {
}

func urlProtocol(_ protocol: URLProtocol, didReceive challenge: URLAuthenticationChallenge) {
NSUnimplemented()
guard let task = `protocol`.task else { fatalError() }
guard let session = task.session as? URLSession else { fatalError() }
Copy link
Member

Choose a reason for hiding this comment

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

Please call fatalError() with a clear error message.

@pushkarnk
Copy link
Member

@saiHemak Please correct the typo in the commit message as well. Thanks.

@pushkarnk
Copy link
Member

@swift-ci please test

@pushkarnk
Copy link
Member

@swift-ci please test and merge

3 similar comments
@pushkarnk
Copy link
Member

@swift-ci please test and merge

@pushkarnk
Copy link
Member

@swift-ci please test and merge

@pushkarnk
Copy link
Member

@swift-ci please test and merge

@swift-ci swift-ci merged commit ba812f3 into swiftlang:master Jul 25, 2018
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

Successfully merging this pull request may close these issues.

4 participants