[GH-ISSUE #488] 'observeCallback' is inaccessible due to 'internal' protection level #320

Closed
opened 2026-03-03 16:47:40 +03:00 by kerem · 2 comments
Owner

Originally created by @geertberkers on GitHub (Sep 3, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/488

Description:

I want to use this library only to get the authorization code, but this is not possible (yet).
I saw the open functions so I want to override the authorize function, but when I do that, I'll get the following error: 'observeCallback' is inaccessible due to 'internal' protection level

I removed the following code from the override function, and used succes to return responseParameters (which contain authorization code)

class OAuth2SwiftAuthCode: OAuth2Swift {
    
   override func authorize(withCallbackURL callbackURL: URL?, scope: String, state: String, parameters: Parameters = [:], headers: OAuthSwift.Headers? = nil, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? {

        self.observeCallback { [weak self] url in
            guard let this = self else {
                OAuthSwift.retainError(failure)
                return
            }
            var responseParameters = [String: String]()
            if let query = url.query {
                responseParameters += query.parametersFromQueryString
            }
            if let code = responseParameters["code"] {
                if !this.allowMissingStateCheck {
                    guard let responseState = responseParameters["state"] else {
                        failure?(OAuthSwiftError.missingState)
                        return
                    }
                    if responseState != state {
                        failure?(OAuthSwiftError.stateNotEqual(state: state, responseState: responseState))
                        return
                    }
                }
                let callbackURLEncoded: URL?
                if let callbackURL = callbackURL {
                    callbackURLEncoded = URL(string: callbackURL.absoluteString.urlEncoded)!
                } else {
                    callbackURLEncoded = nil
                }
                //**NOTE: Replaced this.postOAuthAccessTokenWithRequestToken with succes!**
                success(this.client.credential, nil, responseParameters)
            } else if let error = responseParameters["error"] {
                let description = responseParameters["error_description"] ?? ""
                let message = NSLocalizedString(error, comment: description)
                failure?(OAuthSwiftError.serverError(message: message))
            } else {
                let message = "No access_token, no code and no error provided by server"
                failure?(OAuthSwiftError.serverError(message: message))
            }
        }
    }
}

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

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:

  • objective c

Originally created by @geertberkers on GitHub (Sep 3, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/488 ### Description: I want to use this library only to get the authorization code, but this is not possible (yet). I saw the open functions so I want to override the authorize function, but when I do that, I'll get the following error: 'observeCallback' is inaccessible due to 'internal' protection level I removed the following code from the override function, and used succes to return responseParameters (which contain authorization code) ``` class OAuth2SwiftAuthCode: OAuth2Swift { override func authorize(withCallbackURL callbackURL: URL?, scope: String, state: String, parameters: Parameters = [:], headers: OAuthSwift.Headers? = nil, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? { self.observeCallback { [weak self] url in guard let this = self else { OAuthSwift.retainError(failure) return } var responseParameters = [String: String]() if let query = url.query { responseParameters += query.parametersFromQueryString } if let code = responseParameters["code"] { if !this.allowMissingStateCheck { guard let responseState = responseParameters["state"] else { failure?(OAuthSwiftError.missingState) return } if responseState != state { failure?(OAuthSwiftError.stateNotEqual(state: state, responseState: responseState)) return } } let callbackURLEncoded: URL? if let callbackURL = callbackURL { callbackURLEncoded = URL(string: callbackURL.absoluteString.urlEncoded)! } else { callbackURLEncoded = nil } //**NOTE: Replaced this.postOAuthAccessTokenWithRequestToken with succes!** success(this.client.credential, nil, responseParameters) } else if let error = responseParameters["error"] { let description = responseParameters["error_description"] ?? "" let message = NSLocalizedString(error, comment: description) failure?(OAuthSwiftError.serverError(message: message)) } else { let message = "No access_token, no code and no error provided by server" failure?(OAuthSwiftError.serverError(message: message)) } } } } ``` ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.2.1 - [x] 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: - [ ] objective c
kerem closed this issue 2026-03-03 16:47:41 +03:00
Author
Owner

@phimage commented on GitHub (Sep 3, 2018):

why not override postOAuthAccessTokenWithRequestToken to get the code?
and respond what you want

<!-- gh-comment-id:418120488 --> @phimage commented on GitHub (Sep 3, 2018): why not override `postOAuthAccessTokenWithRequestToken ` to get the code? and respond what you want
Author
Owner

@geertberkers commented on GitHub (Sep 3, 2018):

Well, didn't think of that. Was focused on the authorize function...
Thanks, got a working solution ;)

<!-- gh-comment-id:418129396 --> @geertberkers commented on GitHub (Sep 3, 2018): Well, didn't think of that. Was focused on the authorize function... Thanks, got a working solution ;)
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#320
No description provided.