darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
193 stars 127 forks source link

conflict with twitter auth #6

Closed niypoo closed 4 years ago

niypoo commented 4 years ago

I'm working with twitter auth , but when use this package and set that code

import UIKit
import Flutter
import FBSDKCoreKit // <--- ADD THIS LINE

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)// <--- ADD THIS LINE
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    // <--- OVERRIDE THIS METHOD WITH THIS CODE
    override func application( _ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool { ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation] )
    }
}

the twitter hanging when "redirect to the app" and when remove facebook code in AppDelegate.swift return twitter working again

darwin-morocho commented 4 years ago

could you check the next implementation in your AppDelegate.swift

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let appId: String = Settings.appId
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
return ApplicationDelegate.shared.application(app, open: url, options: options)
}
return false
}
niypoo commented 4 years ago
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let appId: String = Settings.appId
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
return ApplicationDelegate.shared.application(app, open: url, options: options)
}
return false
}

it's give me an error Type 'Settings' has no member 'appId'

darwin-morocho commented 4 years ago
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let appId: String = Settings.appId
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
return ApplicationDelegate.shared.application(app, open: url, options: options)
}
return false
}

it's give me an error Type 'Settings' has no member 'appId'

you need set appId in your ios app in your Settings or set in the AppDelegate.swift

 override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let appId: String = "YOUR_FACEBOOK_APP_ID"
        if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
            return ApplicationDelegate.shared.application(app, open: url, options: options)
        }
        return false
    }
niypoo commented 4 years ago
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let appId: String = Settings.appId
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
return ApplicationDelegate.shared.application(app, open: url, options: options)
}
return false
}

it's give me an error Type 'Settings' has no member 'appId'

you need set appId in your ios app in your Settings or set in the AppDelegate.swift

 override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let appId: String = "YOUR_FACEBOOK_APP_ID"
        if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" {
            return ApplicationDelegate.shared.application(app, open: url, options: options)
        }
        return false
    }

Yes, I understand now thank you I will try now

niypoo commented 4 years ago
Screen Shot 2020-05-06 at 11 16 41 PM

what is my bad here ?1

darwin-morocho commented 4 years ago
Screen Shot 2020-05-06 at 11 16 41 PM

I what is my bad here ?1

Maybe this code is better for you

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        if let facebookAppId: String = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String {
            if url.scheme != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
                return ApplicationDelegate.shared.application(app, open: url, options: options)
           }
        }
        return false
    }

where "FacebookAppID" must be defined in your info.plist

niypoo commented 4 years ago
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        if let facebookAppId: String = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String {
            if url.scheme != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
                return ApplicationDelegate.shared.application(app, open: url, options: options)
           }
        }
        return false
    }

yet this is make the app build success but still twitter not redirect back IMG_4697

darwin-morocho commented 4 years ago
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        if let facebookAppId: String = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String {
            if url.scheme != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
                return ApplicationDelegate.shared.application(app, open: url, options: options)
           }
        }
        return false
    }

yet this is make the app build success but still twitter not redirect back IMG_4697

What plugin or library are you using for twitter auth?

niypoo commented 4 years ago

I'm using that package flutter_twitter_login: git: url: https://github.com/Kiruel/flutter_twitter_login

darwin-morocho commented 4 years ago

I'm using that package flutter_twitter_login: git: url: https://github.com/Kiruel/flutter_twitter_login

This is not an issue (is a bad implementation of developer).

After check this library I am sure that you are not Handling Log in Redirect.

When you use multiples providers of auth you need got to the documentation and follow the implementation.

I've been followed https://github.com/twitter-archive/twitter-kit-ios/wiki/Log-In-With-Twitter

First make sure that you have all Prerequisites https://github.com/twitter-archive/twitter-kit-ios/wiki/Log-In-With-Twitter#prerequisites and added the callback url (twitterkit-<consumer key>://) in your https://apps.twitter.com/ > Go to app settings

next Handling Log in Redirect https://github.com/twitter-archive/twitter-kit-ios/wiki/Log-In-With-Twitter#handling-log-in-redirect

my AppDelegate.swift

import UIKit
import Flutter
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)
import TwitterKit // <--- FOR LOGIN WITH TWITTER ADD THIS LINE (first you need run  pod install)

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)// <--- ADD THIS LINE
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    // <--- OVERRIDE THIS METHOD WITH THIS CODE
    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        if url.scheme != nil {
            let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
            if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId!)") && url.host ==  "authorize" {
                 print("is login by facebook")
                 return ApplicationDelegate.shared.application(app, open: url, options: options)
            } else if url.scheme!.contains("twitter") { // for login by twitter
               print("is login by twitter")
               return TWTRTwitter.sharedInstance().application(app, open: url, options: options)
            }
        }

        return false

    }
}

And login was ok with twitter.

darwin-morocho commented 4 years ago

Please close the issue

niypoo commented 4 years ago
    // <--- OVERRIDE THIS METHOD WITH THIS CODE
    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        if url.scheme != nil {
            let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
            if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId!)") && url.host ==  "authorize" {
                 print("is login by facebook")
                 return ApplicationDelegate.shared.application(app, open: url, options: options)
            } else if url.scheme!.contains("twitter") { // for login by twitter
               print("is login by twitter")
               return TWTRTwitter.sharedInstance().application(app, open: url, options: options)
            }
        }

        return false

    }

Sure I already did all implementation , even I'm log-in with twitter with no error until I used Facebook with Twitter together, show this issue , So I just add that missing snippet

....
 else if url.scheme!.contains("twitter") { // for login by twitter
               return TWTRTwitter.sharedInstance().application(app, open: url, options: options)
            }
...

then all works as a sharm , thank you for great effort