Code Monkey home page Code Monkey logo

saml-service-provider's Introduction

Clojars Project

Ring handlers/middleware for implementing saml authentication. Delegates to onelogin/java-saml for the actual xml validation and parsing. Many thanks to the onelogin team for saving me from the hard parts!


Usage

Here is an example of wiring this middleware into a ring app. Note that ring.middleware.anti-forgery is monkey-patched by this library (if present) to exempt your SAML endpoints that consume form posts from an IDP.

(require '[saml-service-provider.core :as sspc])
(require '[ring.middleware.defaults :as defaults])
(require '[ring.adapter.jetty :as jetty])
(require '[clojure.java.io :as io])

(defn whoami-handler [request]
  (let [saml-data  (:saml-service-provider.core/identity request)
        email-addr (get-in saml-data [:email 0])]
    {:status  200
     :headers {"Content-Type" "text/plain"}
     :body    (format "You're authenticated as %s" email-addr)}))

(def settings
  {:idp-metadata-url
   "http://localhost:7000/metadata"
   :onelogin-settings
   {:onelogin.saml2.sp.x509cert   (slurp (io/resource "sp-public-cert.pem"))
    :onelogin.saml2.sp.privatekey (slurp (io/resource "sp-private-key.pem"))}})

(def application
  (-> whoami-handler
      (sspc/wrap-saml-authentication settings)
      (defaults/wrap-defaults defaults/site-defaults)))

(jetty/run-jetty #'application {:port 3000 :join? false})

Default endpoints are:


INITIATE LOGIN: 
GET /saml/login

ACS CALLBACK: 
POST /saml/acs

SP METADATA:
GET /saml/metadata

INITIATE LOGOUT:
GET /saml/initiate-logout

LOGOUT CALLBACK:
POST /saml/confirm-logout
 

SAML Metadata

This library serves service provider metadata based on your configuration and also supports configuring the authentication middleware using either an idp metadata url or explicit idp settings. I recommend using metadata on both sides because it greatly reduces the burden of SAML setup and miscommunications.


Options

Valid options are exactly those offered by onelogin/java-saml.

This library does provide default values for many options.


License

This project is licensed under MIT license.

saml-service-provider's People

Contributors

rutledgepaulv 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.