[GH-ISSUE #54] Support for Self Signed SSL certificates #36

Closed
opened 2026-03-03 16:45:00 +03:00 by kerem · 8 comments
Owner

Originally created by @acoleman-apc on GitHub (Apr 19, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/54

It would be great if you would factor the code found here:
http://stackoverflow.com/questions/24063927/swift-how-to-request-a-url-with-a-self-signed-certificate

Into your project as it would allow for the use of self-signed SSL certificates with your plug in.

This could would need to be added to the OAuthSwiftHTTPRequest.swift file and re-factored to change the "www.myhost.com" line to match the expected host.

Thanks

Originally created by @acoleman-apc on GitHub (Apr 19, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/54 It would be great if you would factor the code found here: http://stackoverflow.com/questions/24063927/swift-how-to-request-a-url-with-a-self-signed-certificate Into your project as it would allow for the use of self-signed SSL certificates with your plug in. This could would need to be added to the OAuthSwiftHTTPRequest.swift file and re-factored to change the "www.myhost.com" line to match the expected host. Thanks
kerem 2026-03-03 16:45:00 +03:00
Author
Owner

@phimage commented on GitHub (Dec 1, 2015):

NSURLConnection is no more used replaced by NSURLSession with OAuthSwiftHTTPRequest as NSURLSessionDelegate
In the two case there is more to do than stackoverflow code, many way to valid or not (always trust (bad), user/password credential, certificate), count failure, ...

Without an example of server I can't test or develop something, so I will close

If this is necessarry(request it) a delegate parameters could be added to OAuthSwiftHTTPRequest to let framework user custom the behaviours
NSURLSessionTaskDelegate could be used intead of NSURLSessionDelegate

Some code
https://github.com/search?l=swift&q=didReceiveChallenge+&type=Code&utf8=%E2%9C%93
https://gist.github.com/edwardmp/df8517aa9f1752e73353

func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) {
// accept
    completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(forTrust: challenge.protectionSpace.serverTrust))
// or cancel
    completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil)
<!-- gh-comment-id:161025775 --> @phimage commented on GitHub (Dec 1, 2015): `NSURLConnection` is no more used replaced by `NSURLSession` with `OAuthSwiftHTTPRequest` as `NSURLSessionDelegate` In the two case there is more to do than stackoverflow code, many way to valid or not (always trust (bad), user/password credential, certificate), count failure, ... Without an example of server I can't test or develop something, so I will close If this is necessarry(request it) a delegate parameters could be added to `OAuthSwiftHTTPRequest` to let framework user custom the behaviours NSURLSessionTaskDelegate could be used intead of NSURLSessionDelegate Some code https://github.com/search?l=swift&q=didReceiveChallenge+&type=Code&utf8=%E2%9C%93 https://gist.github.com/edwardmp/df8517aa9f1752e73353 ``` swift func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) { // accept completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(forTrust: challenge.protectionSpace.serverTrust)) // or cancel completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil) ```
Author
Owner

@makeitTim commented on GitHub (Sep 18, 2017):

Was this (or a way to set my own delegate) ever implemented?

I am using my own id provider, so in the development environment it's a created SSL cert. So this is needed.

<!-- gh-comment-id:330274611 --> @makeitTim commented on GitHub (Sep 18, 2017): Was this (or a way to set my own delegate) ever implemented? I am using my own id provider, so in the development environment it's a created SSL cert. So this is needed.
Author
Owner

@phimage commented on GitHub (Sep 19, 2017):

@makeitTim
You can set your own url session delegate for all url session created by oauthswift

var sessionFactory = URLSessionFactory.default
sessionFactory.delegate = <your delegate>

And some framework methods use URLSessionFactory as parameter, for advanced use, and use another factory.

<!-- gh-comment-id:330462339 --> @phimage commented on GitHub (Sep 19, 2017): @makeitTim You can set your own url session delegate for all url session created by oauthswift ``` var sessionFactory = URLSessionFactory.default sessionFactory.delegate = <your delegate> ``` And some framework methods use `URLSessionFactory` as parameter, for advanced use, and use another factory.
Author
Owner

@makeitTim commented on GitHub (Sep 19, 2017):

Thanks! I just found the SessionFactory struct and have been trying to figure out how to use it.

Xcode does not like the code you gave me, default can only appear in a switch statement. I cannot get it to run.

The convention for singleton naming in Swift seems to be shared:

public static var shared = URLSessionFactory()
<!-- gh-comment-id:330512618 --> @makeitTim commented on GitHub (Sep 19, 2017): Thanks! I just found the SessionFactory struct and have been trying to figure out how to use it. Xcode does not like the code you gave me, `default can only appear in a switch statement`. I cannot get it to run. The convention for singleton naming in Swift seems to be shared: ``` public static var shared = URLSessionFactory() ```
Author
Owner

@phimage commented on GitHub (Sep 19, 2017):

I agree with naming bug with swift 3 you can use default

I edit the code, by replacing ; by =

<!-- gh-comment-id:330514492 --> @phimage commented on GitHub (Sep 19, 2017): I agree with naming bug with swift 3 you can use `default` I edit the code, by replacing `;` by `=`
Author
Owner

@makeitTim commented on GitHub (Sep 19, 2017):

Thanks for the quick response... I don't follow you? What would allow swift to use a variable named default?

<!-- gh-comment-id:330517717 --> @makeitTim commented on GitHub (Sep 19, 2017): Thanks for the quick response... I don't follow you? What would allow swift to use a variable named `default`?
Author
Owner

@phimage commented on GitHub (Sep 19, 2017):

This not a forbidden keyword, go to the URLSessionFactory code and you will see
Just ass some magic quote and you can use default

<!-- gh-comment-id:330524439 --> @phimage commented on GitHub (Sep 19, 2017): This not a forbidden keyword, go to the `URLSessionFactory` code and you will see Just ass some magic quote and you can use default
Author
Owner

@makeitTim commented on GitHub (Sep 19, 2017):

Ok, I was able to access the session factory with var sessionFactory = URLSessionFactory.default. I have not been able to get a self-signed SSL cert to work, even with implementing a URLSessionDelegate. But I think we're gonna try to get a verified certificate for dev anyways as that's a better way to work and Apple will require it in the end.

Keep up the good work!

<!-- gh-comment-id:330538672 --> @makeitTim commented on GitHub (Sep 19, 2017): Ok, I was able to access the session factory with `var sessionFactory = URLSessionFactory.default`. I have not been able to get a self-signed SSL cert to work, even with implementing a URLSessionDelegate. But I think we're gonna try to get a verified certificate for dev anyways as that's a better way to work and Apple will require it in the end. Keep up the good work!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#36
No description provided.