Skip to content

Commit

Permalink
Merge pull request pac4j#10 from pac4j/iss9
Browse files Browse the repository at this point in the history
iss9
  • Loading branch information
leleuj committed Mar 26, 2015
2 parents cfd776f + 59b528b commit 6755c9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ object Application extends ScalaController {
val urlForm = getRedirectAction(request, newSession, "FormClient", "/?2").getLocation()
val urlBA = getRedirectAction(request, newSession, "BasicAuthClient", "/?3").getLocation()
val urlCas = getRedirectAction(request, newSession, "CasClient", "/?4").getLocation()
val urlGoogleOpenId = getRedirectAction(request, newSession, "GoogleOpenIdClient", "/?5").getLocation()
val urlOidc = getRedirectAction(request, newSession, "OidcClient", "/?5").getLocation()
val urlSaml = getRedirectAction(request, newSession, "Saml2Client", "/?6").getLocation()
val profile = getUserProfile(request)
Ok(views.html.index(profile, urlFacebook, urlTwitter, urlForm, urlBA, urlCas, urlGoogleOpenId, urlSaml)).withSession(newSession)
Ok(views.html.index(profile, urlFacebook, urlTwitter, urlForm, urlBA, urlCas, urlOidc, urlSaml)).withSession(newSession)
}

def facebookIndex = RequiresAuthentication("FacebookClient") { profile =>
Expand Down Expand Up @@ -69,7 +69,7 @@ object Application extends ScalaController {
}
}

def googleOpenIdIndex = RequiresAuthentication("GoogleOpenIdClient") { profile =>
def oidcIndex = RequiresAuthentication("OidcClient") { profile =>
Action { request =>
Ok(views.html.protectedIndex(profile))
}
Expand Down
22 changes: 14 additions & 8 deletions app/controllers/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import play.api.Play.current
import play.api.mvc._
import org.pac4j.play._
import org.pac4j.core.client._
import org.pac4j.core.context._
import org.pac4j.cas.client._
import org.pac4j.saml.client._
import org.pac4j.oauth.client._
import org.pac4j.http.client._
import org.pac4j.openid.client._
import org.pac4j.http.profile._
import org.pac4j.oidc.client._
import org.pac4j.http.credentials._
import play.api.mvc.Results._

Expand All @@ -23,8 +25,8 @@ object Global extends GlobalSettings {
}

override def onStart(app: Application) {
Config.setErrorPage401(views.html.error401.render().toString())
Config.setErrorPage403(views.html.error403.render().toString())
BaseConfig.setErrorPage401(views.html.error401.render().toString())
BaseConfig.setErrorPage403(views.html.error403.render().toString())

val fbId = Play.application.configuration.getString("fbId").get
val fbSecret = Play.application.configuration.getString("fbSecret").get
Expand All @@ -36,8 +38,8 @@ object Global extends GlobalSettings {
val twitterClient = new TwitterClient("HVSQGAw2XmiwcKOTvZFbQ", "FSiO9G9VRR4KCuksky0kgGuo8gAVndYymr4Nl7qc8AA")

// HTTP
val formClient = new FormClient(baseUrl + "/theForm", new SimpleTestUsernamePasswordAuthenticator())
val basicAuthClient = new BasicAuthClient(new SimpleTestUsernamePasswordAuthenticator())
val formClient = new FormClient(baseUrl + "/theForm", new SimpleTestUsernamePasswordAuthenticator(), new UsernameProfileCreator())
val basicAuthClient = new BasicAuthClient(new SimpleTestUsernamePasswordAuthenticator(), new UsernameProfileCreator())

// CAS
val casClient = new CasClient()
Expand All @@ -52,10 +54,14 @@ object Global extends GlobalSettings {
saml2Client.setPrivateKeyPassword("pac4j-demo-passwd")
saml2Client.setIdpMetadataPath("resource:openidp-feide.xml")

// OpenID
val googleOpenIdClient = new GoogleOpenIdClient()
// OpenID Connect
val oidcClient = new OidcClient()
oidcClient.setClientID("343992089165-i1es0qvej18asl33mvlbeq750i3ko32k.apps.googleusercontent.com");
oidcClient.setSecret("unXK_RSCbCXLTic2JACTiAo9");
oidcClient.setDiscoveryURI("https://accounts.google.com/.well-known/openid-configuration");
oidcClient.addCustomParam("prompt", "consent");

val clients = new Clients(baseUrl + "/callback", facebookClient, twitterClient, formClient, basicAuthClient, casClient, saml2Client, googleOpenIdClient)
val clients = new Clients(baseUrl + "/callback", facebookClient, twitterClient, formClient, basicAuthClient, casClient, saml2Client, oidcClient)
Config.setClients(clients)
// for test purposes : profile timeout = 60 seconds
// Config.setProfileTimeout(60)
Expand Down
14 changes: 5 additions & 9 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(profile : org.pac4j.core.profile.CommonProfile, urlFacebook: String, urlTwitter: String, urlForm: String, urlBasicAuth: String, urlCas: String, urlGoogleOpenId: String, urlSaml: String)
@(profile : org.pac4j.core.profile.CommonProfile, urlFacebook: String, urlTwitter: String, urlForm: String, urlBasicAuth: String, urlCas: String, urlOidc: String, urlSaml: String)
<h1>index</h1>
<a href="facebook/index.html">Protected url by Facebook : facebook/index.html</a><br />
<a href="twitter/index.html">Protected url by Twitter : twitter/index.html</a><br />
Expand All @@ -7,10 +7,8 @@ <h1>index</h1>
<a href="basicauth/index.html">Protected url by basic auth : basicauth/index.html</a><br />
<a href="cas/index.html">Protected url by CAS : cas/index.html</a><br />
<a href="saml/index.html">Protected url by SAML : saml/index.html</a><br />
<form action="google-openid/index.html" method="POST">
<input type="text" name="openIdUser" value="https://www.google.com/accounts/o8/id" />
<input type="submit" value="Protected url by Google OpenID: google-openid/index.html" />
</form>
<a href="oidc/index.html">Protected url by OpenId Connect : oidc/index.html</a><br />

<br />
<a href="logout">logout</a>
<br /><br />
Expand All @@ -23,10 +21,8 @@ <h1>index</h1>
<a href="@urlBasicAuth">Authenticate with basic auth</a><br />
<a href="@urlCas">Authenticate with CAS</a><br />
<a href="@urlSaml">Authenticate with SAML</a><br />
<form action="@urlGoogleOpenId" method="POST">
<input type="text" name="openIdUser" value="https://www.google.com/accounts/o8/id" />
<input type="submit" value="Authenticate with Google OpenID" />
</form>
<a href="@urlOidc">Authenticate with OpenId Connect</a><br />

<br />
<br />
<h1>Find the source code on <a target="_blank" href="https://github.com/leleuj/play-pac4j-scala-demo">https://github.com/leleuj/play-pac4j-scala-demo</a><br/>
Expand Down
13 changes: 7 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
"org.pac4j" % "play-pac4j_scala2.11" % "1.3.0",
"org.pac4j" % "pac4j-http" % "1.6.0",
"org.pac4j" % "pac4j-cas" % "1.6.0",
"org.pac4j" % "pac4j-openid" % "1.6.0",
"org.pac4j" % "pac4j-oauth" % "1.6.0",
"org.pac4j" % "pac4j-saml" % "1.6.0",
"org.pac4j" % "play-pac4j_scala2.11" % "1.4.0-SNAPSHOT",
"org.pac4j" % "pac4j-http" % "1.7.0-SNAPSHOT",
"org.pac4j" % "pac4j-cas" % "1.7.0-SNAPSHOT",
"org.pac4j" % "pac4j-openid" % "1.7.0-SNAPSHOT",
"org.pac4j" % "pac4j-oauth" % "1.7.0-SNAPSHOT",
"org.pac4j" % "pac4j-saml" % "1.7.0-SNAPSHOT",
"org.pac4j" % "pac4j-oidc" % "1.7.0-SNAPSHOT",
"com.typesafe.play" % "play-cache_2.11" % "2.3.0"
)

Expand Down
3 changes: 1 addition & 2 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ GET /form/index.html.json controllers.Application.formIndexJson()
GET /basicauth/index.html controllers.Application.basicauthIndex()
GET /cas/index.html controllers.Application.casIndex()
GET /saml/index.html controllers.Application.samlIndex()
GET /google-openid/index.html controllers.Application.googleOpenIdIndex()
POST /google-openid/index.html controllers.Application.googleOpenIdIndex()
GET /oidc/index.html controllers.Application.oidcIndex()
GET /callback org.pac4j.play.CallbackController.callback()
POST /callback org.pac4j.play.CallbackController.callback()
GET /casProxyCallback org.pac4j.play.CallbackController.callback()
Expand Down

0 comments on commit 6755c9b

Please sign in to comment.