user1735414
user1735414

Reputation: 11

OAuthException error in app center mobile authentication

I'm trying to do authentication from app center for mobile devices but I get this error when I try to exchange code parameter for access token:

{
    "error": {
        "message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
        "type": "OAuthException",
        "code": 100
    }
}

Auth token parameter is in Query String format because my app uses server-side authentication.

The url I'm calling is https://graph.facebook.com/oauth/access_token and the redirect_uri parameter I'm sending to is like the following one:

http://www.example.com?ref=app_directory&code=codefromfb&fb_source=appcenter_mobile&fb_appcenter=1

www.example.com is the value I've set in mobile site url field in app settings.

Authentication from app center for web it's ok.

I don't understand what it's wrong in redirect uri form mobile devices...

Could you help me?

Upvotes: 1

Views: 2185

Answers (3)

Redirect URLs that are working for app center authentication

desktop:  http://www.example.com/?fb_source=appcenter&fb_appcenter=1
mobile:   http://www.example.com/?ref=app_directory
          (part fb_source=appcenter_mobile&fb_appcenter=1 should be excluded for mobile, I think that it's FB bug)

Where:

http/https      - depends on request
www.example.com - you should use exactly same string as saved at application settings (https://developers.facebook.com/apps/YOUR_APPLICATION_NUMBER/summary) Domain name is case sensitive for Facebook (also bug)

Upvotes: 1

cgmckeever
cgmckeever

Reputation: 4093

I found this post referencing needing a trailing slash on the URI

redirect_uri error in oauth for facebook django app

Upvotes: 2

Alexander Poleschuk
Alexander Poleschuk

Reputation: 1049

I had the same error. I couldn't solve it but found a workaround: I ignore the code param that is sent to my mobile web app by Facebook automatically; instead I make a request for code myself, then I exchange code for access_token using the same redirect_uri I used to request for code.

To make it easier to apply the workaround, in your app > settings > permissions, you can change Auth Token Parameter from query string to URI fragment. Then Facebook won't send you code param automatically--you will have to make a request for it--that's what is needed.

Another way to solve it is to implement client-side authentification flow using URI fragment or parse URI fragment at the client-side and send access_token to the server as a param. I didn't test this approach yet.

Upvotes: 1

Related Questions