[GH-ISSUE #449] The success or failure handler never gets called though its authorized successfully Magento API #293

Closed
opened 2026-03-03 16:47:27 +03:00 by kerem · 4 comments
Owner

Originally created by @emraz on GitHub (Apr 5, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/449

Description:

I am connecting to Magento API and can authorize the app successfully, however, the success or failure handler never gets called.

AppDelegate:

   func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        OAuth1Swift.handle(url: url as URL)
        return true
    }

    
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        OAuthSwift.handle(url: url)
        return true
    }
    
    @available(iOS 9.0, *)
    func application(app: UIApplication, openURLurl: NSURL, options: [String : AnyObject]) -> Bool {
        OAuthSwift.handle(url: openURLurl as URL)
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
       
        if (url.host == "oauth-callback") {
            OAuthSwift.handle(url: url)
        }
        return true
    }

Login Code:

func doOAuthTwitter(_ serviceParameters: [String:String]){
        let oauthswift = OAuth1Swift(
            consumerKey:    serviceParameters["consumerKey"]!,
            consumerSecret: serviceParameters["consumerSecret"]!,
            requestTokenUrl: "http://highgateair.com.au/oauth/initiate",
            authorizeUrl:    "http://www.highgateair.com.au/oauth/authorize",
            accessTokenUrl:  "http://highgateair.com.au/oauth/token"
        )
        self.oauthswift = oauthswift
        oauthswift.authorizeURLHandler = getURLHandler()
        let _ = oauthswift.authorize(
            withCallbackURL: URL(string: "http://httpbin.org/get")!,
            success: { credential, response, parameters in
                self.showTokenAlert(name: serviceParameters["name"], credential: credential)
        },
            failure: { error in
                print(error.description)
        }
        )
    }

OAuth Provider (Magento):

http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html

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 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 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 @emraz on GitHub (Apr 5, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/449 ### Description: I am connecting to Magento API and can authorize the app successfully, however, the success or failure handler never gets called. AppDelegate: ``` func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { OAuth1Swift.handle(url: url as URL) return true } func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { OAuthSwift.handle(url: url) return true } @available(iOS 9.0, *) func application(app: UIApplication, openURLurl: NSURL, options: [String : AnyObject]) -> Bool { OAuthSwift.handle(url: openURLurl as URL) return true } func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { if (url.host == "oauth-callback") { OAuthSwift.handle(url: url) } return true } ``` Login Code: ``` func doOAuthTwitter(_ serviceParameters: [String:String]){ let oauthswift = OAuth1Swift( consumerKey: serviceParameters["consumerKey"]!, consumerSecret: serviceParameters["consumerSecret"]!, requestTokenUrl: "http://highgateair.com.au/oauth/initiate", authorizeUrl: "http://www.highgateair.com.au/oauth/authorize", accessTokenUrl: "http://highgateair.com.au/oauth/token" ) self.oauthswift = oauthswift oauthswift.authorizeURLHandler = getURLHandler() let _ = oauthswift.authorize( withCallbackURL: URL(string: "http://httpbin.org/get")!, success: { credential, response, parameters in self.showTokenAlert(name: serviceParameters["name"], credential: credential) }, failure: { error in print(error.description) } ) } ``` ### OAuth Provider (Magento): http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html ### OAuth Version: - [x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [x] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 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:27 +03:00
Author
Owner

@phimage commented on GitHub (Apr 5, 2018):

Wrong callback url
This url allow to open your app, using url scheme (that you must configure)

Then retain ´oauthSwift’ object as your class attribute

<!-- gh-comment-id:379036203 --> @phimage commented on GitHub (Apr 5, 2018): Wrong callback url This url allow to open your app, using url scheme (that you must configure) Then retain ´oauthSwift’ object as your class attribute
Author
Owner

@emraz commented on GitHub (Apr 5, 2018):

Thanks for your comment.
Can you please tell me where (server/app) and how I can configure the url/url scheme?

<!-- gh-comment-id:379038623 --> @emraz commented on GitHub (Apr 5, 2018): Thanks for your comment. Can you please tell me where (server/app) and how I can configure the url/url scheme?
Author
Owner

@phimage commented on GitHub (Apr 5, 2018):

Could you please read the readme, and wiki if necessary

<!-- gh-comment-id:379038920 --> @phimage commented on GitHub (Apr 5, 2018): Could you please read the readme, and wiki if necessary
Author
Owner

@emraz commented on GitHub (Apr 5, 2018):

Yes got a solution....
Thanks
https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL

<!-- gh-comment-id:379058789 --> @emraz commented on GitHub (Apr 5, 2018): Yes got a solution.... Thanks https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL
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#293
No description provided.