(Quick Reference)

3 Usage - Reference Documentation

Authors: Pavel Burov

Version: 1.0

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 Vkontakte App credentials, and play with the code.

Usage

Setup Vkontakte credentials

Put your Vkontakte App appId/secret into Config.groovy:

grails.plugin.springsecurity.vkontakte.appId = ..
grails.plugin.springsecurity.vkontakte.secret = ..

Create domain class for your user

Like domain/VkontakteUser.groovy:

class VkontakteUser {
    Long vkId
    String accessToken
    Date accessTokenExpires

static belongsTo = [user: User] // connected to main Spring Security domain

static constraints = { vkId unique: true } }

The plugin is configured for VkontakteUser class name by default. But you could use different name (or use package) for domain class, for example com.company.UserWithVkontakte, that you should configure at Config.groovy at this case:

grails.plugin.springsecurity.vkontakte.domain.className = 'com.company.VkontakteUser'

Put SignIn with Vkontakte button:

Add into your GSP:

<vkontakteAuth:connect />

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> <vkontakteAuth:connect /> </sec:ifNotLoggedIn>