Reputation: 370
I have following in my gsp:
<oauth:connect provider="facebook" params="[currentURL: location.protocol + '//'
+ location.host + location.pathname]">
<img src="../images/socialSites/facebook.png" alt="facebook" />
</oauth:connect>
And following code in controller:
def currentURL = params.currentURL
println "currentURL is :"+currentURL;
and getting this error and page is not displayed:
Caused by: java.lang.NullPointerException: Cannot get property 'protocol' on null object
I read here that oauth can accept all params that g:link can accept, so trying to send current url to controller so as I can redirect to same page after login is successful. How do i make it happen?
Upvotes: 1
Views: 241
Reputation: 7619
You cannot add params
to the connect
tab of oauth taglib
because it is not adding given params
to the URL
.
To achieve your requirement create your custom tag for authentication:
class MyOauthTagLib {
static namespace = 'o'
def connect = { attrs, body ->
String provider = attrs.provider
Map params = attrs.remove('params')
if (!provider) {
throw new GrailsTagException('No provider specified for <o:connect /> tag. Try <o:connect provider="your-provider-name" />')
}
Map a = attrs + [url: [controller: 'oauth', action: 'authenticate', params: [provider: provider] + params]]
out << g.link(a, body)
}
}
and use it in your gsp:
<o:connect provider="facebook" params="[currentURL: request.scheme + '://' + request.serverName + ':' + request.serverPort + request.forwardURI]">facebook</o:connect>
NOTE:- Use request
as suggested by @Burt Beckwith
. You cannot access location
here.
Upvotes: 0
Reputation: 75671
location.protocol
/location.host
/location.pathname
/etc. would work in JavaScript, but inside the params
map only Groovy is supported, and that code has no access to the client-side state. Use
params="[currentURL: request.scheme + '://' + request.serverName + ':' + request.serverPort + request.forwardURI]"
instead.
Upvotes: 1