簡體   English   中英

Grails Spring安全性Oauth2

[英]Grails spring security Oauth2

我在尋找有關grails插件的建議:

  • 春季安全OAuth2
  • Spring Security OAuth2-Google

我正在開發Grails 3.1.9應用程序,需要添加功能齊全的Google登錄按鈕。

  1. 我已經將依賴項添加到我的build.gradle中。

    編譯'org.grails.plugins:spring-security-core:3.1.1'編譯'org.grails.plugins:spring-security-oauth2:1.1.0'編譯'org.grails.plugins:spring-security-oauth2- google:1.1.0'

  2. 在Google中創建了應用程序。

  3. 創建的憑證:

    添加到授權的JavaScript起源

    http://本地主機:8089

    已添加到授權重定向URI中

    http:// localhost:8089 / oauth2 / google / callback

  4. 在application.yml中進行配置。


grails:
    plugin:
        springsecurity:
            oauth2:
                providers:
                     google:
                         api_key: myKey
                         api_secret: mySecret         
                         successUri: /oauth2/google/success    
                         failureUri: /oauth2/google/failure   
                         callback: /oauth2/google/callback    
                active: true    
                registration:
                        askToLinkOrCreateAccountUri: /oauth2/ask 
                        roleNames: ['ROLE_USER'] 
  1. 使用此命令創建新的域類。

grails init-oauth2 myPackage User OAuthID
  1. 將此添加到我的用戶域類。

    靜態hasMany = [oAuthIDs:OAuthID]

  2. 最后將其添加到我的登錄視圖中。


<oauth2:connect provider="google" id="google-connect-link">Google</oauth2:connect>

Logged with google?
<oauth2:ifLoggedInWith provider="google">yes</oauth2:ifLoggedInWith>
<oauth2:ifNotLoggedInWith provider="google">no</oauth2:ifNotLoggedInWith>

問題是,在我單擊通過google登錄后,我的頁面會刷新並轉到/ login / auth。 沒有重定向到Google身份驗證,代碼也從未獲得Oauth2中的回調函數。

有人知道我在做什么錯或缺少什么嗎? 如果有任何建議或示例,我將非常感謝。

您是否添加了OAuthID作為插件所需的參數,如下所示?

grails.plugin.springsecurity.oauth2.domainClass ='myPackage.OAuthID'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM