Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

FacebookContext.getCurrentURL return wrong when my server is begind firewall #80

Open
wureka opened this issue Apr 10, 2017 · 1 comment

Comments

@wureka
Copy link

wureka commented Apr 10, 2017

I use Grails 3.2.8 + Facebook SDk plugins 2.7.3.

When I use the server-redirect way (oauth2) to authenticate a user and If my server is behind a firewall, FacebookContext.getCurrentURL() will return wrong URL.
And this will lead FacebookContextUser.getToken() error. The error is:
Can't Load URL: The domain of this URL isn't included in the app's domains bla bla bla...
"type": "OAuthException",
"code": 191,


          if (code && code != context.session.getData('code')) {
                    _token = getTokenFromCode(code, context.currentURL)
                    log.debug "Got token from server side redirect params code (token=$_token)"
                    if (!_token) {
                        // Code was bogus, so everything based on it should be invalidated.
                        invalidate()
                    }
                } else {
                    // Falling back on persistent store, knowing nothing explicit (signed request, authorization code, etc.) was present to shadow it (or we saw a code in URL/FORM scope, but it's the same as what's in the persistent store)
                    _token = context.session.getData('token', '')
                }

Currently, the workaround way is to change FacebookContext.getCurrentURL in BootStrap like below code:

import grails.plugin.facebooksdk.FacebookContext 
import grails.util.Environment
class BootStrap {
    def init = { servletContext ->
        FacebookContext.metaClass.getCurrentURL = {->
            switch (Environment.current) {
                case Environment.DEVELOPMENT:
                    return "http://localhost:8080/website/index";
                default:
                    return "http://mysite.mydomain.net/fb-callback";
            }
        }
    }
    def destroy = {
    }
}

@benorama
Copy link
Member

benorama commented Jun 3, 2017

The issue is coming from

grailsLinkGenerator.link(
                absolute: true,
                action: request.params.action,
                controller: request.params.controller,
                params: params
 )

Did you try to dig into Grails doc to override the domain used by this utility to see if you can override it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants