Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #187 from joscha/oauth2-test
Browse files Browse the repository at this point in the history
Oauth2 test
  • Loading branch information
joscha committed Jun 29, 2014
2 parents 683af48 + 8e0fed6 commit 34fd77b
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
1.sql
/.target
github-buttons
test-env.sh
repo
37 changes: 27 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
language: scala
scala:
- 2.10.4
- 2.11.1
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script:
- "cd $TRAVIS_BUILD_DIR/code"
- "sbt ++$TRAVIS_SCALA_VERSION test"
- "sbt ++$TRAVIS_SCALA_VERSION publish-local"
- "cd $TRAVIS_BUILD_DIR/test-app"
- "sbt ++$TRAVIS_SCALA_VERSION test"
- "cd $TRAVIS_BUILD_DIR/samples/java/play-authenticate-usage"
- "sbt ++$TRAVIS_SCALA_VERSION test"
- "cd $TRAVIS_BUILD_DIR/samples/java/play-authenticate-simple-oauth"
- "sbt ++$TRAVIS_SCALA_VERSION test"
- cd $TRAVIS_BUILD_DIR/code
- sbt --warn ++$TRAVIS_SCALA_VERSION compile
- sbt ++$TRAVIS_SCALA_VERSION test
- sbt --warn ++$TRAVIS_SCALA_VERSION publish-local
- cd $TRAVIS_BUILD_DIR/test-app
- sbt --warn ++$TRAVIS_SCALA_VERSION compile
- sbt ++$TRAVIS_SCALA_VERSION test
- cd $TRAVIS_BUILD_DIR/samples/java/play-authenticate-usage
- sbt --warn ++$TRAVIS_SCALA_VERSION compile
- if [[ "$TRAVIS_SECURE_ENV_VARS" == "true" ]]; then sbt --info ++$TRAVIS_SCALA_VERSION test;
fi
- cd $TRAVIS_BUILD_DIR/samples/java/play-authenticate-simple-oauth
- sbt --warn ++$TRAVIS_SCALA_VERSION compile
- sbt ++$TRAVIS_SCALA_VERSION test
notifications:
email: false
email: false
env:
global:
# GOOGLE_USER_PASSWORD
- secure: gm1FnnjROan7Fbq3ezsa49W1OpwgQBjPslBaWvubG8cx3EceYmnwmT1IaM2v+WnbU+MldODhQI9rNYluv6pkrKQRvu7oif3L0G+kbNvA/FGVNXwcraAQSv8duxmvu/bcB3MfoiKmlkNrGXqGJ4Cg2g/kNRQMj/kseYNCDLfKeY4=
# GOOGLE_CLIENT_ID
- secure: eL98QzlGDfnX2y2kgPa9LN52kA2FevZmpD5KqghU0rMBm8lNO1/cHYQ6d8nsAI12MPi7ZAenOWppd525/SmUqoQgVOFVjahG4K1OKKHPf5XMrE/rkxgOOXhTTZsHsagecOV3GM8oR1IweOs7+/fWNArJXagDtq3k1/Ztd8V66cQ=
# GOOGLE_CLIENT_SECRET
- secure: kNTriQH573IT4ikQ4LoVV9f7HlxHctKKye/dNwivvqrMPR4JXV6NzBj19nTwWJfOreGCMaYNXcPusF+t+ySZ2HI0TszaxmYFID8MPQlaclut1RguZ9H1nu4U02shk+dGI6kv8wftswRDSyfDRHuiFRMSedgnh+rNYzx6BKJLCL0=
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ The included sample application shows how to use all of those providers.

## Versions
* **TRUNK** [not released in the repository, yet]
**0.6.1-SNAPSHOT** [2014-06-29]
* Add Scala 2.10.x binary to repository
* Test against Scala 2.10.x
* Fix repository URLs
* Added simple OAuth2 test
* **0.6.0-SNAPSHOT** [2014-06-10]
* First release for Play 2.3.x
* Japanese localization (thanks @naruoga)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class GoogleAuthProvider extends
OAuth2AuthProvider<GoogleAuthUser, GoogleAuthInfo> {

static final String PROVIDER_KEY = "google";
public static final String PROVIDER_KEY = "google";

private static final String USER_INFO_URL_SETTING_KEY = "userInfoUrl";

Expand Down
54 changes: 28 additions & 26 deletions code/app/com/feth/play/module/pa/service/UserServicePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
import com.feth.play.module.pa.user.AuthUser;

public abstract class UserServicePlugin extends Plugin implements UserService {

private Application application;

public UserServicePlugin(final Application app) {
application = app;
}

protected Application getApplication() {
return application;
}

@Override
public void onStart() {
if(PlayAuthenticate.hasUserService()) {
Logger.warn("A user service was already registered - replacing the old one, " +
"however this might hint to a configuration problem if this is a production environment.");
}
PlayAuthenticate.setUserService(this);
}

@Override
public AuthUser update(AuthUser knownUser) {
// Default: just do nothing when user logs in again
return knownUser;
}
}

private Application application;

public UserServicePlugin(final Application app) {
application = app;
}

protected Application getApplication() {
return application;
}

@Override
public void onStart() {
if (PlayAuthenticate.hasUserService()) {
final String oldServiceClass = PlayAuthenticate.getUserService().getClass().getName();

Logger.warn("A user service was already registered - replacing the old one (" + oldServiceClass + ") with the new one (" + getClass().getName() + "), " +
"however this might hint to a configuration problem if this is a production environment.");
}
PlayAuthenticate.setUserService(this);
}

@Override
public AuthUser update(AuthUser knownUser) {
// Default: just do nothing when user logs in again
return knownUser;
}
}
15 changes: 11 additions & 4 deletions code/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ name := "play-authenticate"

scalaVersion := "2.11.1"

version := "0.6.0-SNAPSHOT"
crossScalaVersions := Seq("2.10.4", "2.11.1")

version := "0.6.1-SNAPSHOT"

publishTo <<= (version) { version: String =>
if (version.trim.endsWith("SNAPSHOT")) Some(Resolver.file("file", new File( "../repo/snapshots" )))
else Some(Resolver.file("file", new File( "../repo/releases" )))
}

libraryDependencies ++= Seq(
"org.apache.httpcomponents" % "httpclient" % "4.3.4",
"com.feth" %% "play-easymail" % "0.6.0-SNAPSHOT",
"com.feth" %% "play-easymail" % "0.6.1-SNAPSHOT",
"org.mindrot" % "jbcrypt" % "0.3m",
"commons-lang" % "commons-lang" % "2.6",
javaCore,
Expand All @@ -19,8 +26,8 @@ libraryDependencies ++= Seq(
resolvers ++= Seq(
"Apache" at "http://repo1.maven.org/maven2/",
"jBCrypt Repository" at "http://repo1.maven.org/maven2/org/",
Resolver.url("play-easymail (release)", url("http://joscha.github.io/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-easymail (snapshot)", url("http://joscha.github.io/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns)
"play-easymail (release)" at "http://joscha.github.io/play-easymail/repo/releases/",
"play-easymail (snapshot)" at "http://joscha.github.io/play-easymail/repo/snapshots/"
)

publishArtifact in packageDoc := false
Expand Down
2 changes: 2 additions & 0 deletions code/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
sbt +publish
10 changes: 5 additions & 5 deletions samples/java/play-authenticate-simple-oauth/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ scalaVersion := "2.11.1"
version := "1.0-SNAPSHOT"

val appDependencies = Seq(
"com.feth" %% "play-authenticate" % "0.6.0-SNAPSHOT",
"com.feth" %% "play-authenticate" % "0.6.1-SNAPSHOT",
javaCore,
cache,
javaWs,
Expand All @@ -17,10 +17,10 @@ val appDependencies = Seq(
resolvers ++= Seq(
"Apache" at "http://repo1.maven.org/maven2/",
"jBCrypt Repository" at "http://repo1.maven.org/maven2/org/",
Resolver.url("play-easymail (release)", url("http://joscha.github.io/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-easymail (snapshot)", url("http://joscha.github.io/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns),
Resolver.url("play-authenticate (release)", url("http://joscha.github.io/play-authenticate/repo/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-authenticate (snapshot)", url("http://joscha.github.io/play-authenticate/repo/snapshots/"))(Resolver.ivyStylePatterns)
"play-easymail (release)" at "http://joscha.github.io/play-easymail/repo/releases/",
"play-easymail (snapshot)" at "http://joscha.github.io/play-easymail/repo/snapshots/",
"play-authenticate (release)" at "http://joscha.github.io/play-authenticate/repo/releases/",
"play-authenticate (snapshot)" at "http://joscha.github.io/play-authenticate/repo/snapshots/"
)

lazy val root = (project in file("."))
Expand Down
4 changes: 3 additions & 1 deletion samples/java/play-authenticate-usage/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Play Authenticate sample Java application
# Play Authenticate sample Java application

By default there is only the UsernamePassword and the OpenID provider enabled, as all other providers need some additional settings that have to be acquired from the according service (Google, Facebook, etc.) - please check the `conf/play.plugins` file to enable more providers and add your data to `conf/play-authenticate/mine.conf`.
20 changes: 10 additions & 10 deletions samples/java/play-authenticate-usage/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
<html lang="@lang().code()">
<head>
<title>@title</title>

<!-- Le meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Play Authenticate - an authentication module for the Play! Framework 2.0">
<meta name="author" content="The Play Authenticate Team">

<!-- Le scripts -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="@routes.Assets.at("js/bootstrap.min.js")"></script>
<script src="@routes.Application.jsRoutes" defer="defer"></script>

<!-- Le styles -->
<link href="@routes.Assets.at("stylesheets/main.min.css")" rel="stylesheet">
<link href="@routes.Assets.at("css/main.css")" rel="stylesheet">
<link href="@routes.Assets.at("css/bootstrap.min.css")" rel="stylesheet">


<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
Expand All @@ -42,7 +42,7 @@
<span class="icon-bar"></span>
</a>
<a class="brand" href="@routes.Application.index()">Play! Authenticate</a>

<div class="btn-group pull-right">
@subjectPresentOr() {
@defining(Application.getLocalUser(session())) { user =>
Expand All @@ -62,12 +62,12 @@
}
</div>


<div class="nav-collapse">
<ul class="nav">
<li class="@("active".when(nav == ""))"><a href="@routes.Application.index()">@Messages("playauthenticate.navigation.home")</a></li>
<li class="@("active".when(nav == "restricted"))"><a href="@routes.Application.restricted()">@Messages("playauthenticate.navigation.restricted")</a></li>

@subjectNotPresent() {
<li class="@("active".when(nav == "signup"))"><a href="@routes.Application.signup()">@Messages("playauthenticate.navigation.signup")</a></li>
}
Expand All @@ -89,11 +89,11 @@
</div>
}
@content

<hr>

<footer>
<p>&copy; 2012-2013 Play! Authenticate. Licensed under Apache License, Version 2.0. View details <a href="https://github.com/joscha/play-authenticate/blob/master/LICENSE">here</a>.</p>
<p>&copy; 2012-2014 Play! Authenticate. Licensed under Apache License, Version 2.0. View details <a href="https://github.com/joscha/play-authenticate/blob/master/LICENSE">here</a>.</p>
<p>
<small>Styles by <a href="http://twitter.github.com/bootstrap/index.html" target="_blank">Twitter Bootstrap</a> &middot; Provider icons by <a href="https://github.com/paulrobertlloyd/socialmediaicons/" target="_blank">Paul Robert Lloyd</a></small></p>
</footer>
Expand Down
29 changes: 15 additions & 14 deletions samples/java/play-authenticate-usage/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import play.PlayJava

name := "play-authenticate-usage"

scalaVersion := "2.11.1"
Expand All @@ -6,8 +8,8 @@ version := "1.0-SNAPSHOT"

val appDependencies = Seq(
"be.objectify" %% "deadbolt-java" % "2.3.0-RC1",
// Comment this for local development of the Play Authentication core:
"com.feth" %% "play-authenticate" % "0.6.0-SNAPSHOT",
// Comment the next line for local development of the Play Authentication core:
"com.feth" %% "play-authenticate" % "0.6.1-SNAPSHOT",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
javaCore,
cache,
Expand All @@ -19,22 +21,21 @@ val appDependencies = Seq(
resolvers ++= Seq(
"Apache" at "http://repo1.maven.org/maven2/",
"jBCrypt Repository" at "http://repo1.maven.org/maven2/org/",
Resolver.url("play-easymail (release)", url("http://joscha.github.io/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-easymail (snapshot)", url("http://joscha.github.io/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns),
"play-easymail (release)" at "http://joscha.github.io/play-easymail/repo/releases/",
"play-easymail (snapshot)" at "http://joscha.github.io/play-easymail/repo/snapshots/",
Resolver.url("Objectify Play Repository", url("http://schaloner.github.io/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-authenticate (release)", url("http://joscha.github.io/play-authenticate/repo/releases/"))(Resolver.ivyStylePatterns),
Resolver.url("play-authenticate (snapshot)", url("http://joscha.github.io/play-authenticate/repo/snapshots/"))(Resolver.ivyStylePatterns)
"play-authenticate (release)" at "http://joscha.github.io/play-authenticate/repo/releases/",
"play-authenticate (snapshot)" at "http://joscha.github.io/play-authenticate/repo/snapshots/"
)

lazy val root = (project in file("."))
// Uncomment the next line for local development of the Play Authenticate core:
//lazy val playAuthenticate = project.in(file("modules/play-authenticate")).enablePlugins(PlayJava)

lazy val root = project.in(file("."))
.enablePlugins(PlayJava)
.settings(
libraryDependencies ++= appDependencies
)

// Uncomment this for local development of the Play Authenticate core:
// lazy val playAuthenticate = (project in file("modules/play-authenticate")).enablePlugins(PlayJava)

// root
// .dependsOn(playAuthenticate)
// .aggregate(playAuthenticate)
// Uncomment the next lines for local development of the Play Authenticate core:
//.dependsOn(playAuthenticate)
//.aggregate(playAuthenticate)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SMTP mailer settings
smtp {
# TODO: Disable this in production
mock=true
# SMTP server
# (mandatory)
Expand All @@ -23,4 +24,4 @@ smtp {
# Optional, comment this line to leave password blank
# defaults to no password
password=password
}
}
20 changes: 10 additions & 10 deletions samples/java/play-authenticate-usage/conf/play.plugins
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
1500:com.typesafe.plugin.CommonsMailerPlugin
10000:be.objectify.deadbolt.java.DeadboltPlugin
10005:service.MyUserServicePlugin
10010:com.feth.play.module.pa.providers.oauth2.google.GoogleAuthProvider
10020:com.feth.play.module.pa.providers.oauth2.facebook.FacebookAuthProvider
10030:com.feth.play.module.pa.providers.oauth2.foursquare.FoursquareAuthProvider
#10010:com.feth.play.module.pa.providers.oauth2.google.GoogleAuthProvider
#10020:com.feth.play.module.pa.providers.oauth2.facebook.FacebookAuthProvider
#10030:com.feth.play.module.pa.providers.oauth2.foursquare.FoursquareAuthProvider
10040:providers.MyUsernamePasswordAuthProvider
10050:com.feth.play.module.pa.providers.openid.OpenIdAuthProvider
10060:com.feth.play.module.pa.providers.oauth1.twitter.TwitterAuthProvider
10070:com.feth.play.module.pa.providers.oauth1.linkedin.LinkedinAuthProvider
10080:com.feth.play.module.pa.providers.oauth2.vk.VkAuthProvider
10090:com.feth.play.module.pa.providers.oauth1.xing.XingAuthProvider
10100:com.feth.play.module.pa.providers.oauth2.untappd.UntappdAuthProvider
10110:com.feth.play.module.pa.providers.oauth2.pocket.PocketAuthProvider
10120:com.feth.play.module.pa.providers.oauth2.github.GithubAuthProvider
#10060:com.feth.play.module.pa.providers.oauth1.twitter.TwitterAuthProvider
#10070:com.feth.play.module.pa.providers.oauth1.linkedin.LinkedinAuthProvider
#10080:com.feth.play.module.pa.providers.oauth2.vk.VkAuthProvider
#10090:com.feth.play.module.pa.providers.oauth1.xing.XingAuthProvider
#10100:com.feth.play.module.pa.providers.oauth2.untappd.UntappdAuthProvider
#10110:com.feth.play.module.pa.providers.oauth2.pocket.PocketAuthProvider
#10120:com.feth.play.module.pa.providers.oauth2.github.GithubAuthProvider
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}

form .error {
input {
form .error input {
background-color: #F2DEDE;
border-color: #EED3D7;
color: #B94A48;
}
.help-inline {
}

form .error .help-inline {
color: #B94A48;
}
}

.providers {
margin: 5px 0;
list-style: none;
li {
display: inline;
}
margin: 5px 0;
list-style: none;
}

.providers li {
display: inline;
}

.help-block {
margin: -10px 0 10px 0;
font-size: 10px;
color: #ccc !important;
margin: -10px 0 10px 0;
font-size: 10px;
color: #ccc !important;
}

h1 {
margin-bottom: 20px !important;
}
margin-bottom: 20px !important;
}
Loading

0 comments on commit 34fd77b

Please sign in to comment.