Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authorize callback not called #15

Closed
natecraft1 opened this issue Sep 17, 2020 · 3 comments
Closed

authorize callback not called #15

natecraft1 opened this issue Sep 17, 2020 · 3 comments

Comments

@natecraft1
Copy link

In my ViewController:

class ViewController: NSViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        do {
            try GAppAuth.shared.authorize { (success) in
                // never called
            }
        } catch {
            print(error)
        }
    }

What happens is that it pops Safari, and when I sign in with my email, it just lands me on google.com and the callback is not called. Could it be an issue with the redirect URI? Also, why it doesn't use the default browser? Is that configurable?

Thanks!

@elsesiy
Copy link
Owner

elsesiy commented Dec 23, 2020

@natecraft1 Thanks for filing this issue. This certainly sounds like an issue with your redirect URI as I cannot reproduce it on my end. The browser used is not configurable as this is handled by AppAuth afaik. Let me know if you need further assistance and if so please provide a reproduction of the issue that I can look at, thanks!

@elsesiy elsesiy closed this as completed Dec 23, 2020
@kangadrewie
Copy link

@natecraft1 Did you manage to solve this issue in the end? I've been experiencing the same issue. Callback is never called.

@natecraft1
Copy link
Author

@natecraft1 Did you manage to solve this issue in the end? I've been experiencing the same issue. Callback is never called.

I did - it was a while ago. I think it was a code issue. I dug into the example project on this repo and found I was missing some code (it should probably be in the readme)

Make sure you have this below and let me know if that solves it.

class AppDelegate: NSObject, NSApplicationDelegate {

    var window: NSWindow!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        FirebaseApp.configure()

        // Handle URL event
        NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
        
        GAppAuth.shared.appendAuthorizationRealm(OIDScopeEmail)
        
        // Retrieve existing auth
        GAppAuth.shared.retrieveExistingAuthorizationState()
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }

    @objc private func handleEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
        let urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue ?? ""
        let url = URL(string: urlString)!
        
        _ = GAppAuth.shared.continueAuthorization(with: url, callback: nil)
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants