Permalink
Browse files

Fixed OAuth Plugin so it works with OAuth 1.0 and added Twitter examp…

…le to verify.
  • Loading branch information...
Matt Raible
Matt Raible committed Dec 23, 2009
1 parent c5387aa commit 6db20f3b8341383b869f49d6ca126ebd99ccb364
@@ -1,5 +1,5 @@
#utf-8
-#Tue Dec 22 11:53:29 MST 2009
+#Tue Dec 22 23:49:18 MST 2009
plugins.oauth=0.2
app.version=0.1
app.servlet.version=2.4
@@ -35,7 +35,7 @@ grails.enable.native2ascii = true
// set per-environment serverURL stem for creating absolute links
environments {
production {
- grails.serverURL = "http://demo.raibledesigns.com/grails-oauth"
+ grails.serverURL = "http://demo.raibledesigns.com/${appName}"
}
development {
grails.serverURL = "http://localhost:8080/${appName}"
@@ -56,27 +56,34 @@ log4j = {
//}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
- 'org.codehaus.groovy.grails.web.pages', // GSP
- 'org.codehaus.groovy.grails.web.sitemesh', // layouts
- 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
- 'org.codehaus.groovy.grails.web.mapping', // URL mapping
- 'org.codehaus.groovy.grails.commons', // core / classloading
- 'org.codehaus.groovy.grails.plugins', // plugins
- 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
- 'org.springframework',
- 'org.hibernate'
+ 'org.codehaus.groovy.grails.web.pages', // GSP
+ 'org.codehaus.groovy.grails.web.sitemesh', // layouts
+ 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
+ 'org.codehaus.groovy.grails.web.mapping', // URL mapping
+ 'org.codehaus.groovy.grails.commons', // core / classloading
+ 'org.codehaus.groovy.grails.plugins', // plugins
+ 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
+ 'org.springframework',
+ 'org.hibernate'
warn 'org.mortbay.log'
}
oauth {
- linkedin {
- requestTokenUrl="https://api.linkedin.com/uas/oauth/requestToken"
- accessTokenUrl="https://api.linkedin.com/uas/oauth/accessToken"
- authUrl="https://api.linkedin.com/uas/oauth/authorize"
- consumer.key="h1vdy1qwYP9sFc9pCba5E9EgsQvFp49xNNpH44qtI2FMX9gUUvB1wq1efEpZAZuD"
- consumer.secret="IWCcU97gRcWpMkzFvwW5VhAq1qFPLhXRfC1OqUYAy8O3yyncsp89I-pUGM5z6E9D"
- }
+ linkedin {
+ requestTokenUrl="https://api.linkedin.com/uas/oauth/requestToken"
+ accessTokenUrl="https://api.linkedin.com/uas/oauth/accessToken"
+ authUrl="https://api.linkedin.com/uas/oauth/authorize"
+ consumer.key="h1vdy1qwYP9sFc9pCba5E9EgsQvFp49xNNpH44qtI2FMX9gUUvB1wq1efEpZAZuD"
+ consumer.secret="IWCcU97gRcWpMkzFvwW5VhAq1qFPLhXRfC1OqUYAy8O3yyncsp89I-pUGM5z6E9D"
+ }
+ twitter {
+ requestTokenUrl="http://twitter.com/oauth/request_token"
+ accessTokenUrl="http://twitter.com/oauth/access_token"
+ authUrl="http://twitter.com/oauth/authorize"
+ consumer.key="jXds3ENr7sslQAe50HOA"
+ consumer.secret="i4bztzzxkqiwOIlTtrIPgvsR5yX9uW3GQSWrRJsSC0c"
+ }
}
@@ -21,7 +21,15 @@
<g:oauthLink consumer='linkedin' returnTo="[controller:'profile']">
<h3>Login with
<img src="http://static.raibledesigns.com/repository/images/linkedin-logo.gif" width="129" height="36"
- style="border: 0; float: right"/></h3>
+ style="border: 0; float: right"/></h3>
+ </g:oauthLink>
+ </div>
+
+ <div style="margin-left: 20px; margin-top: 20px; width: 240px; padding-top: 10px; margin-top: 30px">
+ <g:oauthLink consumer="twitter" returnTo="[controller:'timeline']">
+ <h3>Login with
+ <img src="http://static.raibledesigns.com/repository/images/twitter-logo.png" width="155" height="36"
+ style="border: 0; float: right"></h3>
</g:oauthLink>
</div>
</body>
@@ -88,7 +88,11 @@ class OauthController {
def oauth_verifier = params?.oauth_verifier
try{
- def accessToken = oauthService.fetchAccessToken(redirParams.consumer, [key:session.oauthToken.key, secret:session.oauthToken.secret, verifier:oauth_verifier])
+ def accessToken
+ if (oauth_verifier)
+ accessToken = oauthService.fetchAccessToken(redirParams.consumer, [key:session.oauthToken.key, secret:session.oauthToken.secret, verifier:oauth_verifier])
+ else
+ accessToken = oauthService.fetchAccessToken(redirParams.consumer, [key:session.oauthToken.key, secret:session.oauthToken.secret])
session.oauthToken = accessToken
log.debug("Got access token: ${accessToken.key}\nGot token secret: ${accessToken.secret}\nOAuth Verifier: ${oauth_verifier}")
log.debug("Saved token to session: [key]${session.oauthToken.key} [secret]${session.oauthToken.secret}")
@@ -176,7 +176,11 @@ class OauthService implements InitializingBean{
accessor.requestToken = requestToken.key
accessor.tokenSecret = requestToken.secret
- def accessUrl = consumer.serviceProvider.accessTokenURL + "?oauth_verifier=" + requestToken.verifier
+ def accessUrl
+ if (requestToken.verifier)
+ accessUrl = consumer.serviceProvider.accessTokenURL + "?oauth_verifier=" + requestToken.verifier
+ else
+ accessUrl = consumer.serviceProvider.accessTokenURL
def req = accessor.newRequestMessage("POST", accessUrl, [oauth_token:accessor.requestToken].entrySet())
OAuthResponseMessage response = (OAuthResponseMessage) oauthClient.access(req, ParameterStyle.QUERY_STRING)
def accessToken = response.getParameter("oauth_token");
View
@@ -1,4 +1,4 @@
-<plugin name='oauth' version='0.2' grailsVersion='1.1.1 &gt; *'>
+<plugin name='oauth' version='0.2' grailsVersion='1.1.2 &gt; *'>
<author>Yong Rong (Damien) Hou</author>
<authorEmail>houyongr@gmail.com</authorEmail>
<title>Adds OAuth capability to Grails apps</title>

0 comments on commit 6db20f3

Please sign in to comment.