I've been trying to implement Facebook OAuth from here: http://alvarosanchez.github.io/grails-spring-security-rest/latest/docs/index.html#_delegating_authentication_to_oauth_providers
I'm able to integrate OAuth and get the access token from Facebook but I'm facing problem implementing a custom OAuthUserDetailsService. I've created a custom service:
FacebookOauthUserDetails.groovy
class FacebookOauthUserDetailsService implements OauthUserDetailsService{
@Delegate
UserDetailsService userDetailsService
UserDetailsChecker preAuthenticationChecks
@Override
OauthUser loadUserByUserProfile(CommonProfile userProfile, Collection<GrantedAuthority> defaultRoles) throws UsernameNotFoundException {
UserDetails userDetails
OauthUser oauthUser
println("adss")
try {
println("Trying to fetch user details for user profile: ${userProfile}")
userDetails = userDetailsService.loadUserByUsername(userProfile.id)
log.debug("Checking user details with ${preAuthenticationChecks.class.name}")
preAuthenticationChecks?.check(userDetails)
Collection<GrantedAuthority> allRoles = userDetails.authorities + defaultRoles
oauthUser = new OauthUser(userDetails.username, userDetails.password, allRoles, userProfile)
} catch (UsernameNotFoundException unfe) {
println("User not found. Creating a new one with default roles: ${defaultRoles}")
oauthUser = new OauthUser(userProfile.id, 'N/A', defaultRoles, userProfile)
}
return oauthUser
}
}
the official documentation mentions that in order to override the default behavior one needs to define it in resources.groovy with bean name oauthUserDetailsService.This is how my resources.groovy file looks like:
resources.groovy:
import hungr.FacebookOauthUserDetailsService
import hungr.UserPasswordEncoderListener
beans =
{
userPasswordEncoderListener(UserPasswordEncoderListener)
oauthUserDetailsService(FacebookOauthUserDetailsService)
}
I've tried to refer to this doc here on how to define a bean : https://docs.grails.org/latest/guide/spring.html but it didn't work out for me either. What am I doing wrong?