1 Introduction - Reference Documentation
Authors: Peter Ledbrook
Version: 0.3
1 Introduction
Welcome to the Shiro OAuth plugin for Grails! If you're using the core Shiro plugin in your application already and you want easy authentication via Twitter, Facebook, et al. then this is the plugin for you. It simplifies the integration of OAuth authentication via the Scribe OAuth plugin into the Shiro security framework.Getting Started
Start by adding the plugin as a dependency toBuildConfig.groovy:plugins {
compile ":shiro-oauth:0.2"
}Config.groovy file:oauth {
providers {
twitter {
provider = org.scribe.builder.api.TwitterApi
key = 'consumer key'
secret = 'consumer secret'
callback = "${grails.serverURL}/oauth/twitter/callback"
successUri = '/oauth/success?provider=twitter'
failureUri = '/unauthorized'
} facebook {
…
}
}
}security.shiro.oauth.linkAccountUrl = "/oauth/linkaccount"successUri, but make sure that it maps to the ShiroOAuthController's onSuccess action and that the provider URL parameter is included. Use whatever you want for the failureUri setting.For the callback URL, we recommend /oauth/<provider>/callback which automatically maps to the OauthController's callback action (note the different capitalisation of the controller name). Note that it must be an absolute URL. If you want to map your own URL, make sure to include the provider parameter:"/oauth/success"(controller: "shiroOAuth", action: "onSuccess") "/oauth/callback/$provider"(controller: "oauth", action: "callback")
security.shiro.oauth.* is specifically for this plugin. The linkAccountUrl should map to a page that allows users to link their OAuth identities to internal Shiro accounts. You have to code this page yourself, but once you have the username and password for an internal Shiro account, be it a new one or an existing one, then you can forward the request to another action provided by the plugin:def linkAccount() {
def user = …
forward controller: "shiroOAuth", action: "linkAccount", params: [username: params.username, password: params.password]
}def linkAccount() {
SecurityUtils.subject.login params.username, params.password
forward controller: "shiroOAuth", action: "linkAccount"
}<oauth:connect provider="twitter">Log in with Twitter</oauth:connect>