Coder Social home page Coder Social logo

scalatra-openid-provider-support's Introduction

Scalatra OpenID Provider Support

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

Scalatra

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

https://github.com/scalatra/scalatra

OpenID4Java

OpenID4Java allows you to OpenID-enable your Java webapp.

http://code.google.com/p/openid4java/

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("http://www.example.com/openid/" + 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 = {
    render("confirm",
      "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", "https://www.example.com/opeind/ax/username", "Alice"),
    AXAttribute("gender", "https://www.example.com/opeind/ax/gender", "Female")
  )

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

}

License

Apache License, Version 2.0

http://www.apache.org/licenses/LICENSE-2.0.html

scalatra-openid-provider-support's People

Contributors

seratch avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.