My 'access_token' from facebook is "incorrect value"

1.3k views Asked by At

I'm using django-rest-auth which is "API extension for Django all-auth". I'm building a mobile app which can signup/login using Facebook token (url: http://localhost:8000/rest-auth/facebook/).

  1. get Facebook token using 'expo'

    export const doFacebookLogin = () => async dispatch => {
      let { type, token } = await Facebook.logInWithReadPermissionsAsync('194632xxxxxx', {
          permissions: ['public_profile']
      });
    
      if (type === 'cancel') {
        return dispatch({ type: FACEBOOK_LOGIN_CANCEL })
      }
      doSocialAuthLogin(dispatch, token);
    };
    
  2. Include token in Http POST request

    const doSocialAuthLogin = async (dispatch, token) => {
      console.log(token);
      axios.post(`${ROOT_URL}/rest-auth/facebook/`, {
        access_token: token
      }).then(response => {
        AsyncStorage.setItem('stylee_token', response.data.token);
        dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response.data.token });
      })
      .catch(response => {
        if(response.status === 400) {
          console.log('Not authorized. ');
        } else if (response.status === 403){
          console.log('You are not suposed to see this message. Contact Administrator');
        }
        dispatch({ type: SOCIAL_FACEBOOK_LOGIN_FAIL });
      });
    }
    
  3. I got 400 error. So I printed the token tested on localhost browser and Postman. And both returns

    {
        "non_field_errors": [
            "Incorrect value"
        ]
    }
    

Why am I getting 400 Incorrect value error?

  • settings.py

    SITE_ID = 7 # I searched for corresponding SITE_ID from shell.

  • admin

    Social_Application. =>

    provider: Facebook
    name: ~
    Client id:~
    Secret Key: ~
    Chosen Sites: 'http://localhost:8000'
    

I think I put wrong value for 'access_token'. Can't we put token from expo.Facebook.logInWithReadPermissionsAsync?. Since FB token changes over time.

1

There are 1 answers

0
crawler On

In the admin page for the social app (http://localhost:8000/admin/socialaccount/socialapp/1/change/), you need to specify the "secret key" for Facebook provider.