[GH-ISSUE #467] URLSessionFactory delegate is assigned but never called #304

Closed
opened 2026-03-03 16:47:33 +03:00 by kerem · 1 comment
Owner

Originally created by @ynechaev on GitHub (Jun 4, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/467

Description:

URLSessionFactory delegate is never called, however the delegate is assigned properly and may be observed in runtime. This makes it impossible to debug connections with Charles proxy via self signed SSL.
code:

var sessionFactory = URLSessionFactory.default
sessionFactory.delegate = self

po output:

▿ URLSessionFactory
  ▿ delegate : Optional<NSURLSessionDelegate>
    ▿ some : <Demo.ViewController: 0x7fe90d005b10>
  - isNetworkActivityIndicatorVisible : true

delegate handler:

    internal func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust{
            let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(URLSession.AuthChallengeDisposition.useCredential,credential);
        }
    }

OAuth Provider? (Twitter, Github, ..):

Any

OAuth Version:

  • Version 1
  • Version 2

OS:

  • iOS : 11.3

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2.1
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 9.3 (Swift 4.1)

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @ynechaev on GitHub (Jun 4, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/467 ### Description: URLSessionFactory delegate is never called, however the delegate is assigned properly and may be observed in runtime. This makes it impossible to debug connections with Charles proxy via self signed SSL. code: ```swift var sessionFactory = URLSessionFactory.default sessionFactory.delegate = self ``` po output: ``` ▿ URLSessionFactory ▿ delegate : Optional<NSURLSessionDelegate> ▿ some : <Demo.ViewController: 0x7fe90d005b10> - isNetworkActivityIndicatorVisible : true ``` delegate handler: ```swift internal func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust{ let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!) completionHandler(URLSession.AuthChallengeDisposition.useCredential,credential); } } ``` ### OAuth Provider? (Twitter, Github, ..): Any ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS: - [x] iOS : 11.3 ### Installation method: - [x] Carthage - [ ] CocoaPods - [ ] Manually ### Library version: - [x] head - [ ] v1.2.1 - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 9.3 (Swift 4.1) - [ ] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:47:33 +03:00
Author
Owner

@phimage commented on GitHub (Jun 25, 2018):

delegate is used in any URLSession
but URLSessionFactory is a struct so when you do

var sessionFactory = URLSessionFactory.default

you create a new instance of URLSessionFactory
You do not edit the one used

The correct way to do it is to edit the OAuthSwiftClient attribute sessionFactory, because each client/connection to a provider could have is own session management

so you can do

var sessionFactory = URLSessionFactory.default
sessionFactory.delegate = self
oauthSwiftObject.client.sessionFactory=sessionFactory
<!-- gh-comment-id:399882685 --> @phimage commented on GitHub (Jun 25, 2018): delegate is used in any URLSession but URLSessionFactory is a struct so when you do ```swift var sessionFactory = URLSessionFactory.default ``` you create a new instance of `URLSessionFactory` You do not edit the one used The correct way to do it is to edit the `OAuthSwiftClient` attribute `sessionFactory`, because each client/connection to a provider could have is own session management so you can do ```swift var sessionFactory = URLSessionFactory.default sessionFactory.delegate = self oauthSwiftObject.client.sessionFactory=sessionFactory ```
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#304
No description provided.