agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

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

Open wureka opened 7 years ago

wureka commented 7 years ago

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 commented 7 years ago

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?