简体   繁体   English

从Grails控制器/服务获取OpenID URL

[英]Getting the OpenID URL from a Grails Controller/Service

I'm using acegi 0.5.2 and enabled OpenID support. 我正在使用acegi 0.5.2并启用了OpenID支持。 I would like to know how to accesss the URL (or username) returned by a provider (ie Google, Yahoo!). 我想知道如何访问提供商(例如Google,Yahoo!)返回的URL(或用户名)。 I can't find any docs about that so I traced the code of acegi and found this in GrailsOpenIdAuthenticationProvider: 我找不到与此有关的任何文档,因此我追踪了acegi的代码,并在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. 似乎response.identityUrl包含我需要的东西。 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. acegi插件为您的项目提供了一个LoginController,它具有以下操作:authfail。 inside its implementation, you can check the OpenID value thru this code: 在其实现内部,您可以通过以下代码检查OpenID值:

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. 这样,您就可以自动创建新的用户记录,或使用提供商提供的OpenID进行任何所需的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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