react native FaceBook SDK get token for IOS is returning wrong signature

Viewed 272

I am using the latest Facebook SDK react-native-fbsdk-next, I managed to make it work for Android, but it is not working for IOS

            LoginManager.logInWithPermissions([
              'public_profile',
              'instagram_basic',
              'instagram_manage_insights',
              'pages_show_list',
              'ads_management',
              'business_management',
              'ads_read',
              'read_insights',
            ]).then(
              (result: any) => {
                if (result.isCancelled) {
                  console.log('Login cancelled');
                } else {
                  if (Platform.OS === 'ios') {
                    AuthenticationToken.getAuthenticationTokenIOS().then(
                      (data: any) => {
                        console.log(
                          'after get accress token ',
                          data?.authenticationToken.toString(),
                        );

                        console.log(
                          'Login success with permissions: ' +
                            result.grantedPermissions.toString(),
                        );
                        //data.accessToken.toString()
                        dispatch(fetchPages(data?.authenticationToken));
                      },
                    );
                  }

I am getting a token, but when ever I try to use it to fetch pages, I get wrong signature. Any suggestions what might be the error? what I'm doing wrong.

const manager = new GraphRequestManager();
    const igAccountFields =
      'instagram_business_account{id,name,username,profile_picture_url},id,username,name,tasks,category,access_token';
    const req = new GraphRequest(
      '/me/accounts',
      {
        httpMethod: 'GET',
        accessToken: accessToken,
        parameters: {
          fields: {
            string: igAccountFields,
          },
        },
      },
      _responseInfoCallback,
    );
    manager.addRequest(req);
    manager.start();```
1 Answers

I had a similar error using ruby's fb_graph2 gem raising Bad signature error.

I found facebook documentation states apple does not allow moving the token to the server. It can explain why it works on android but not on iOS.
https://developers.facebook.com/docs/facebook-login/guides/access-tokens#portabletokens

So it seems like you should fetch the user profile on the client side, send it with token to your server, verify the token to see if the profile is legit.

I hope it helps.

Related