seratch / scalatra-openid-provider-support   2.2.0


Scalatra OpenID Provider Support

Scala versions: 2.10

Scalatra OpenID Provider Support

This is an extension to Scalatra to build OpenID Provider application with OpenID4Java.


Scalatra is a tiny, Sinatra-like web framework for Scala. Here are some contributed extensions to the library.


OpenID4Java allows you to OpenID-enable your Java webapp.

How to use

Added library dependency to sbt settings.

"com.github.seratch" %% "scalatra-openid-provider-support" % "2.0.0"

And then mix OpenIDProviderSupport to ScalatraServlet/ScalatraFilter.

The following is not complete code, just an image.

import scalatraext.openidprovider._

class MyServlet extends ScalatraServlet
  with OpenIDProviderSupport
  with AXSupport
  with Logging {

  protected override lazy val baseUrl = "http://localhost:8080"
  protected override lazy val endpointPath = "/auth"
  protected override lazy val identityPathPrefix = "/user/*"
  protected override lazy val confirmationParameterName = "confirmed"
  protected override lazy val isImmediateModeAllowed = true

  protected override def authenticatedIdentity(): Option[Identity] = {
    session.get("identity").map(id => Identity(id.toString))

  protected override def authenticate(): Option[Identity] = {
    UserService.authenticate(params).map { case (id) =>
      Some("" + id)
    }.getOrElse { halt(400, render("loginForm")) }

  protected override def loginFormBodyOrRedirect(): Any = {
    render("login", "openidParams" -> parameterList.asJava)
    // or redirect to the login page with openid params

  protected override def confirmationFormBody(): String = {
      "relam" -> parameterList.getParameter("openid.realm").getValue,
      "returnTo" -> parameterList.getParameter("openid.return_to").getValue,
      "openidParams" -> parameterList.asJava

  protected override def ax(identity: String): Seq[AXAttribute] = Seq(
    AXAttribute("username", "", "Alice"),
    AXAttribute("gender", "", "Female")

  get("/user/Alice") { status(200) } // identity url



Apache License, Version 2.0