Facebook OAuth “Unsupported” in Chrome on iOS

后端 未结 7 1749
我寻月下人不归
我寻月下人不归 2020-12-01 04:38

The Facebook OAuth popup is throwing an error in Chrome on iOS only. Both developers.facebook.com and google have turned up nothing about this. Ideas?

7条回答
  •  长情又很酷
    2020-12-01 04:51

    Here is a complete workaround for your FB JS Auth on Chrome iOS issue http://seanshadmand.com/2015/03/06/facebook-js-login-on-chrome-ios-workaround/

    JS functions to check auth, open FB auth page manually and refresh auth tokens on original page once complete:

    function openFBLoginDialogManually(){
      // Open your auth window containing FB auth page 
      // with forward URL to your Opened Window handler page (below)
    
      var redirect_uri = "&redirect_uri=" + ABSOLUTE_URI + "fbjscomplete";
      var scope = "&scope=public_profile,email,user_friends";
      var url = "https://www.facebook.com/dialog/oauth?client_id=" + FB_ID + redirect_uri + scope;
    
      // notice the lack of other param in window.open
      // for some reason the opener is set to null
      // and the opened window can NOT reference it
      // if params are passed. #Chrome iOS Bug
      window.open(url);
    
    }
    
    function fbCompleteLogin(){
    
      FB.getLoginStatus(function(response) {
        // Calling this with the extra setting "true" forces
        // a non-cached request and updates the FB cache.
        // Since the auth login elsewhere validated the user
        // this update will now asyncronously mark the user as authed
      }, true);
    
    }
    
    function requireLogin(callback){
    
        FB.getLoginStatus(function(response) {
            if (response.status != "connected"){
                showLogin();
            }else{
                checkAuth(response.authResponse.accessToken, response.authResponse.userID, function(success){
                  // Check FB tokens against your API to make sure user is valid
                });
            }
        });
    
    }
    

    And the Opener Handler that FB auth forwards to and calls a refresh to the main page. Note the window.open in Chrome iOS has bugs too so call it correctly as noted above:

    
    
    
    
        

    . . .

提交回复
热议问题