开发者

Getting the OpenID URL from a Grails Controller/Service

开发者 https://www.devze.com 2022-12-23 12:21 出处:网络
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 (i.e. Google, Yahoo!). I can\'t find any docs about that so I traced

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 (i.e. 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 = respons开发者_如何学Pythone.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号