[GH-ISSUE #507] oauth sign in with facebook app #333

Closed
opened 2026-03-03 16:47:46 +03:00 by kerem · 1 comment
Owner

Originally created by @sandeepk000 on GitHub (Jan 16, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/507

here is my code
with normal safari browser it is working but not with facebook app.i tried the process mentioned in native app thread which was opened 2 years before nut it didnt work.pls help

let oauthswift = OAuth2Swift(
consumerKey: "167108074192100", // [1] Enter google app settings
consumerSecret: "", // No secret required
authorizeUrl: "https://www.facebook.com/dialog/oauth",
accessTokenUrl: "https://graph.facebook.com/oauth/access_token",
responseType: "token"
)

    var isFacebookAppInstalled: Bool = {
        let appUrl = URL(string: "fbauth2://app")
        return UIApplication.shared.canOpenURL(appUrl!)
    }()
    
    oauthswift.allowMissingStateCheck = true
    oauthswift.authorizeURLHandler = NativeAppHandler.sharedInstance
    let state = generateState(withLength: 20)
    guard let rwURL = URL(string:"fbauth2://authorize?response_type=token&client_id=167108074192100&redirect_uri=fb167108074192100://oauth-callback") else { return }
    //https://graph.facebook.com/oauth/authorize?response_type=token&client_id=167108074192100&redirect_uri=fb167108074192100://oauth-callback

    let _ = oauthswift.authorize(withCallbackURL: rwURL, scope: "public_profile", state: state, success: { (credential, response, parameters) in
        print("\(credential)\(response)\(parameters)")
        let _ = oauthswift.client.get(
            "https://graph.facebook.com/me?",
            parameters: ["fields": "id, name, first_name, last_name, email"],
            success: { response in
                let dataString = response.string!
                print(dataString)
        }, failure: { error in
            print(error)
        })

    }) { (error) in
        self.presentAlert("error", message: error.localizedDescription)
    }

class NativeAppHandler: OAuthSwiftURLHandlerType {
public static var sharedInstance : NativeAppHandler = NativeAppHandler()

@objc open func handle(_ url: URL) {
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        // Fallback on earlier versions
    }
}

}

I got this message in webview even i want to open facebook app i got this webview only:
Can't Load ULR: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

Originally created by @sandeepk000 on GitHub (Jan 16, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/507 here is my code with normal safari browser it is working but not with facebook app.i tried the process mentioned in native app thread which was opened 2 years before nut it didnt work.pls help let oauthswift = OAuth2Swift( consumerKey: "167108074192100", // [1] Enter google app settings consumerSecret: "", // No secret required authorizeUrl: "https://www.facebook.com/dialog/oauth", accessTokenUrl: "https://graph.facebook.com/oauth/access_token", responseType: "token" ) var isFacebookAppInstalled: Bool = { let appUrl = URL(string: "fbauth2://app") return UIApplication.shared.canOpenURL(appUrl!) }() oauthswift.allowMissingStateCheck = true oauthswift.authorizeURLHandler = NativeAppHandler.sharedInstance let state = generateState(withLength: 20) guard let rwURL = URL(string:"fbauth2://authorize?response_type=token&client_id=167108074192100&redirect_uri=fb167108074192100://oauth-callback") else { return } //https://graph.facebook.com/oauth/authorize?response_type=token&client_id=167108074192100&redirect_uri=fb167108074192100://oauth-callback let _ = oauthswift.authorize(withCallbackURL: rwURL, scope: "public_profile", state: state, success: { (credential, response, parameters) in print("\(credential)\(response)\(parameters)") let _ = oauthswift.client.get( "https://graph.facebook.com/me?", parameters: ["fields": "id, name, first_name, last_name, email"], success: { response in let dataString = response.string! print(dataString) }, failure: { error in print(error) }) }) { (error) in self.presentAlert("error", message: error.localizedDescription) } class NativeAppHandler: OAuthSwiftURLHandlerType { public static var sharedInstance : NativeAppHandler = NativeAppHandler() @objc open func handle(_ url: URL) { if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { // Fallback on earlier versions } } } I got this message in webview even i want to open facebook app i got this webview only: Can't Load ULR: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.
kerem closed this issue 2026-03-03 16:47:47 +03:00
Author
Owner

@phimage commented on GitHub (Jan 16, 2019):

Please stop posting, you already open an issue with not enough information and you do it again...
Try on stackoverflow or test demo app...

<!-- gh-comment-id:454717960 --> @phimage commented on GitHub (Jan 16, 2019): Please stop posting, you already open an issue with not enough information and you do it again... Try on stackoverflow or test demo app...
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#333
No description provided.