简体   繁体   中英

Getting the OpenID URL from a Grails Controller/Service

I'm using acegi 0.5.2 and enabled OpenID support. I would like to know how to accesss the URL (or username) returned by a provider (ie Google, Yahoo!). I can't find any docs about that so I traced the code of acegi and found this in GrailsOpenIdAuthenticationProvider:

OpenIDAuthenticationToken response = (OpenIDAuthenticationToken) authentication
OpenIDAuthenticationStatus status = response.status

// handle the various possibilites
if (status == OpenIDAuthenticationStatus.SUCCESS) {
 // Lookup user details
 UserDetails userDetails = _userDetailsService.loadUserByUsername(response.identityUrl)
 return new GrailsOpenIdAuthenticationToken(userDetails, response.status, response.identityUrl)
}

it seems that the response.identityUrl contains what i need. How can get it from a controller's (or service's) space?

Thanks.

after a very long research and doing several trial and errors, i've found the solution.

acegi plugin provides a LoginController for your project and it has this action: authfail. inside its implementation, you can check the OpenID value thru this code:

println "openid = ${session['SPRING_SECURITY_LAST_EXCEPTION'].extraInformation}"

with that, you can then automatically create a new User record or do anything you want with the OpenID given by a provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM