Grails spring-security-oauth-google:如何设置

时间:2016-12-27 04:56:25

标签: grails spring-security google-oauth spring-security-oauth2

我已安装以下插件

compile 'org.grails.plugins:spring-security-core:3.1.1'
compile "org.grails.plugins:spring-security-oauth2:1.1.0"
compile "org.grails.plugins:spring-security-oauth2-google:1.1.0"

Spring安全核心正常运行。 但我在实施oauth-google身份验证时遇到了问题。

插件文档说我们需要传递api_key和api_secret。我在console.developers.google.com中创建了一个项目并创建了API Key和Oauth Keys,我对在application.yml中使用哪些值感到困惑。 因为根据console.developers.google.com,API密钥和Oauth密钥是单独的凭据。

关于从哪里获取以及如何设置以下值的任何建议都会有所帮助。

api_key: 'AIzaSyBjfn345tg6j0ol1e89kHMOY'               
api_secret: 'xseettDDNtjjuutrfuAFTe4d'  
successUri: "/oauth2/google/success"   
failureUri: "/oauth2/google/failure"   
callback: "/oauth2/google/callback"     
scopes: "some_scope"

1 个答案:

答案 0 :(得分:0)

  1. api_keyapi_secret

    我从console.cloud.google.com /

    中获取了这些密钥

    API Manager>证书>创建/编辑条目

    然后客户端ID和客户端密钥是所需的值。其他参数是Grails应用程序本身内的路径,我相信如果要覆盖插件的默认行为,可以更改这些路径。

  2. 但还有更多......

    1. 请记住将回调地址列入白名单(在同一个面板上完成)。对于本地连接,我将其设置为(在Google API Manager上) http://localhost:8080/oauth2/google/callback

    2. 请注意,除了调用grails s2-quickstart com.yourapp User Role之外,您还需要致电grails init-oauth2 ...(此处描述 - https://github.com/MatrixCrawler/grails-spring-security-oauth2)。

    3. 我接下来要做的是覆盖默认登录页面,以便能够显示此处提到的链接https://github.com/MatrixCrawler/grails-spring-security-oauth2-google <oauth2:connect provider="google" id="google-connect-link">Google</oauth2:connect>。默认值为https://github.com/grails-plugins/grails-spring-security-core/tree/master/grails-app/views/login,您只需将它们复制到grails-app / views / login /并进行修改即可。

    4. 下一个问题是第2点的脚本未向用户域添加static hasMany = [oAuthIDs: OAuthID]字段,导致ask视图提交崩溃。

    5. 之后,Google Oauth2身份验证对我有用。