简体   繁体   中英

Grails using Google authentication with the Spring Security plugin

Has anybody managed to successfully combine Google authentication with Burt Beckwith's awesome Grails-based Spring Security plugin recently? I wanted to go down that path with Grails 2.4.3, and after some fooling around (and recompiling the donbeave version of the plugin at https://github.com/donbeave/grails-spring-security-oauth-google ) I was able to find a combination of references that would compile and run together. I ended up adding the following lines to my BuildConfig.groovy:

compile ':spring-security-core:2.0-RC4'
compile ":spring-security-oauth:2.1.0-RC4"
compile ':spring-security-oauth-google:0.3.1'

I found, however, that the changes created by the initialization command “grails s2-init-oauth” don't give me all the modifications that I need in order to move forward. I ended up adding a block to my config.groovy that looked like this:

oauth {
    providers {
        google {
            api = org.grails.plugin.springsecurity.oauth.GoogleApi20
            key = 'MY KEY'
            secret = 'MY SECRET'
            successUri = '/oauth/google/success'
            failureUri = '/oauth/google/error'
            callback = "${baseURL}/oauth/google/callback"
            scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
        }
    }
}

These config definitions specify a callback in my code (referred to above as ./oauth/google/callback) which didn't exist. After I brought in a controller from the recommended example ( https://github.com/bagage/grails-google-authentification-example ), substituted "/springSecurityOAuth/onSuccess" for "/oauth/google/callback", (and registered by redirect URL through the Google Developers Console) I found that my onSuccess method was indeed being called, but the data structures referenced in the controller were wrong, and it seemed as if I would need to largely rewrite the controller logic in order to get everything working. I have to assume that other people want to accomplish Google-based authentication in the same way that I do. Is there an complete operational example somewhere? Or can someone tell me where I've gone wrong in my attempt to utilize the standard plug-ins? Thanks for any assistance.

You need to use spring security oauth plugin also. Please refer here https://github.com/cazacugmihai/grails-spring-security-oauth ,

When you click on button, it hits the authenticate action inside Oauth controller which gets authentication() url of the google. After successful authentication, it hits callback() action Of Oauth controller which then redirects to onSuccess() action of SpringSecurityOauthController which then saves the info to OAuthId domain and finally redirects to the successUri given in config.

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