3 Usage - Reference Documentation
Authors: Igor Artamonov
Version: 0.6
3 Usage
Example app
You can take a look at Example Application , it's very basic app, that shows how to use the plugin. Just clone it, put your Twitter App credentials, and play with the code.Usage
Install plugin
Add dependencies intoBuildConfig.groovy:plugins {
runtime "org.grails.plugins:resources:1.1.6"
compile "org.grails.plugins:spring-security-core:2.0-RC2" compile "org.grails.plugins:spring-security-twitter:0.6"
}Setup Twitter credentials
Put your Twitter API Consumer Key/Secret intoConfig.groovy:
grails.plugin.springsecurity.twitter.consumerKey=.. grails.plugin.springsecurity.twitter.consumerSecret=..
Create domain class for your user
Likedomain/TwitterUser.groovy:class TwitterUser { /**
* Twitter Username (notice that it could be modified by user, Twitter allows that)
*/
String username /**
* Twitter User Id
*/
Long twitterId /**
* Twitter API token
*/
String token /**
* Twitter API secret
*/
String tokenSecret /**
* Related to main App User
*/
static belongsTo = [user: User] static constraints = {
twitterId(unique: true, nullable: false)
username(nullable: false, blank: false)
}}TwitterUser class name by default. But you could use different name (or use package) for domain class,
for example com.company.UserWithTwitter, that you should configure at Config.groovy at this case:
grails.plugin.springsecurity.twitter.domain.classname='com.company.UserWithTwitter'
Put SignIn with Twitter button:
Add into your GSP:<twitterAuth:button />
Use Spring Security
Now you could use all security tools provided by Spring Security Core.For example, you could use taglib for checking user state:<sec:ifLoggedIn>
<div class="message">Authenticated</div>
Hello <sec:username/>!
</sec:ifLoggedIn><sec:ifNotLoggedIn>
<div class="message">Not authenticated</div>
<twitterAuth:button />
</sec:ifNotLoggedIn>