[GH-ISSUE #362] Example with authorize in class and not in ViewController #229

Closed
opened 2026-03-03 16:46:52 +03:00 by kerem · 10 comments
Owner

Originally created by @GlitchEclipse on GitHub (Apr 15, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/362

Description:

I have created a singleton of a custom class that holds the authorization and returns data fine, but I am trying to figure out with the provided examples how to use the authorizeURLHandler to create the webview when the authorization for the callback is not the ViewController since opening a separate Safari page will not be approved by the App Store. The example is everything done in the ViewController for these actions. Are there any examples don't included everything in one ViewController?

OAuth Provider (Twitter, Github, ..):

Etsy

OAuth Version:

  • Version 1
  • [] Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

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

Xcode version:

  • 8.0 (Swift 3.0)

  • 8.0 (Swift 2.3)

  • 7.3.1

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

  • objective c

Originally created by @GlitchEclipse on GitHub (Apr 15, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/362 ### Description: I have created a singleton of a custom class that holds the authorization and returns data fine, but I am trying to figure out with the provided examples how to use the authorizeURLHandler to create the webview when the authorization for the callback is not the ViewController since opening a separate Safari page will not be approved by the App Store. The example is everything done in the ViewController for these actions. Are there any examples don't included everything in one ViewController? ### OAuth Provider (Twitter, Github, ..): Etsy ### 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 - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem 2026-03-03 16:46:52 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@phimage commented on GitHub (Apr 15, 2017):

for app store if your app is >= ios9 you have the SafariURLHandler

you need a view... to see a webview. so you have a parent view controller. could be one that already exist, a new one just to display the webview and anything else

<!-- gh-comment-id:294290057 --> @phimage commented on GitHub (Apr 15, 2017): for app store if your app is >= ios9 you have the SafariURLHandler you need a view... to see a webview. so you have a parent view controller. could be one that already exist, a new one just to display the webview and anything else
Author
Owner

@oshitub123 commented on GitHub (Apr 26, 2017):

it is okay but what happen when you use ios10 and xcode 8.3.2 we can't use correctly SafariUrlHandler because cause this error :

2017-04-25 12:05:03.680 pruebaslibrary[7476:136239] Warning: Attempt to present <SFSafariViewController: 0x7fdf8ef02960> on <pruebaslibrary.ViewController: 0x7fdf8ef07420> whose view is not in the window hierarchy!

<!-- gh-comment-id:297453451 --> @oshitub123 commented on GitHub (Apr 26, 2017): it is okay but what happen when you use ios10 and xcode 8.3.2 we can't use correctly SafariUrlHandler because cause this error : 2017-04-25 12:05:03.680 pruebaslibrary[7476:136239] Warning: Attempt to present <SFSafariViewController: 0x7fdf8ef02960> on <pruebaslibrary.ViewController: 0x7fdf8ef07420> whose view is not in the window hierarchy!
Author
Owner

@phimage commented on GitHub (Apr 26, 2017):

look for the error in issue

the message is clear, you present it from a bad view controller
you make SFSafariViewController(viewController: XXX, and XXX is not the current view controller

I think I will add a closure, to get this controller....allowing to get the current one

<!-- gh-comment-id:297456709 --> @phimage commented on GitHub (Apr 26, 2017): look for the error in issue the message is clear, you present it from a bad view controller you make SFSafariViewController(viewController: XXX, and XXX is not the current view controller I think I will add a closure, to get this controller....allowing to get the current one
Author
Owner

@oshitub123 commented on GitHub (Apr 26, 2017):

i put this
code:

    let safari = SafariURLHandler(viewController: self,oauthSwift:oauthswift!)
    safari.delegate = self as! SFSafariViewControllerDelegate
    oauthswift.authorizeURLHandler = safari
<!-- gh-comment-id:297497036 --> @oshitub123 commented on GitHub (Apr 26, 2017): i put this code: let safari = SafariURLHandler(viewController: self,oauthSwift:oauthswift!) safari.delegate = self as! SFSafariViewControllerDelegate oauthswift.authorizeURLHandler = safari
Author
Owner

@oshitub123 commented on GitHub (Apr 26, 2017):

but still don't work @phimage

<!-- gh-comment-id:297498343 --> @oshitub123 commented on GitHub (Apr 26, 2017): but still don't work @phimage
Author
Owner

@phimage commented on GitHub (Apr 26, 2017):

I will not help
Please read all my advice

<!-- gh-comment-id:297535512 --> @phimage commented on GitHub (Apr 26, 2017): I will not help Please read all my advice
Author
Owner

@phimage commented on GitHub (Jun 4, 2017):

I try to explain again and close

SafariURLHandler(viewController: VCXXX : VCXXX must be the viewController on top of all view controllers, the one displayed when you make authorize(...,

<!-- gh-comment-id:306030664 --> @phimage commented on GitHub (Jun 4, 2017): I try to explain again and close `SafariURLHandler(viewController: VCXXX` : VCXXX must be the viewController on top of all view controllers, the one displayed when you make `authorize(...`,
Author
Owner

@oshitub123 commented on GitHub (Jun 5, 2017):

i solve this , the problem was that i try to do it into viewdidload but when we use xcode 8.3.2 we have to do it into @IBAction or a func that its called into @ ibaction

<!-- gh-comment-id:306227383 --> @oshitub123 commented on GitHub (Jun 5, 2017): i solve this , the problem was that i try to do it into viewdidload but when we use xcode 8.3.2 we have to do it into @IBAction or a func that its called into @ ibaction
Author
Owner

@oshitub123 commented on GitHub (Jun 5, 2017):

some like this

@IBAction func check(_ sender: Any) {
autorizathion { (bo) in
self.reponseAuth = bo

    }
}
func autorizathion(completionHandler: @escaping (Bool) -> ()) {
   
    oauthswift = OAuth2Swift(
        consumerKey:    "************",
        consumerSecret: "",
        authorizeUrl:"https://accounts.spotify.com/authorize",
        responseType:"token"
    )
    
    let safari = SafariURLHandler(viewController: self,oauthSwift:oauthswift!)
    safari.delegate = self as!SFSafariViewControllerDelegate
    oauthswift?.authorizeURLHandler = safari
    oauthswift?.authorize(withCallbackURL: "DriverLocation://sputir/twitter", scope: "", state: "", success: { (credential, response,parameters) in
       self.userval.saveToken(tkn: credential.oauthToken)
        print(self.userval.queryToken())
        completionHandler(true)
    }, failure: { error in
        print(error._code)
        completionHandler(false)
    }
        
    )
    
}
<!-- gh-comment-id:306228226 --> @oshitub123 commented on GitHub (Jun 5, 2017): some like this @IBAction func check(_ sender: Any) { autorizathion { (bo) in self.reponseAuth = bo } } func autorizathion(completionHandler: @escaping (Bool) -> ()) { oauthswift = OAuth2Swift( consumerKey: "************", consumerSecret: "", authorizeUrl:"https://accounts.spotify.com/authorize", responseType:"token" ) let safari = SafariURLHandler(viewController: self,oauthSwift:oauthswift!) safari.delegate = self as!SFSafariViewControllerDelegate oauthswift?.authorizeURLHandler = safari oauthswift?.authorize(withCallbackURL: "DriverLocation://sputir/twitter", scope: "", state: "", success: { (credential, response,parameters) in self.userval.saveToken(tkn: credential.oauthToken) print(self.userval.queryToken()) completionHandler(true) }, failure: { error in print(error._code) completionHandler(false) } ) }
Author
Owner

@oshitub123 commented on GitHub (Jun 9, 2017):

so thanks for all @phimage

<!-- gh-comment-id:307429182 --> @oshitub123 commented on GitHub (Jun 9, 2017): so thanks for all @phimage
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#229
No description provided.