Giter Site home page Giter Site logo

grwlf / urweb-persona Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doublec/urweb-persona

0.0 3.0 0.0 132 KB

Persona authentication example in Ur/Web

License: BSD 2-Clause "Simplified" License

Haskell 14.83% C 78.47% C++ 2.23% JavaScript 4.47%

urweb-persona's Introduction

Example of using Persona in Ur/Web
==================================

This is a simple example of using Persona in Ur/Web. It is based on the
Persona Quick Setup [1] and portions of the Ur/Web OpenId library [2].

I created this to get a minimal working example of using Persona from
Ur/Web and a 'real' application would want to add more session and
user management.

[1] https://developer.mozilla.org/en-US/Persona/Quick_Setup
[2] http://hg.impredicative.com/openid

Usage
=====

Run 'make' to build. It requires a recent Ur/Web [3] version, 
libjansson [4] and libcurl [5]. The Makefile creates a binary
that uses SQLite [6] for the session database. The steps to
build, create the database and run are:

$ make
$ sqlite3 persona <persona.sql
$ ./persona.exe

The example requires a file 'urweb_persona.js' to be served
by an external web server. I use 'nginx' and set it up to
reverse proxy to the 'persona' example. The 'nginx' config
looks like:

server {
  listen 80;
  server_name 127.0.0.1;

  location /urweb_persona.js {
    root /home/chris/src/ur/persona/;
  }
  
  location / {
    proxy_pass http://127.0.0.1:8080/;
  }
}

Accessing 'http://127.0.0.1/main' will run the example.

[3] http://www.impredicative.com/ur/
[4] http://www.digip.org/jansson/
[5] http://curl.haxx.se/libcurl/
[6] http://www.sqlite.org/

Code Overview
=============

Ur/Web doesn't contain any API for doing HTTP requests and Persona needs
to contact a validation server to validate authentication. To work around
this I use the FFI to wrap libcurl to make the request and libjansson to
parse the JSON response. The FFI code for this is in:

  ffi.c
  ffi.h
  ffi.urs

The Ur/Web FFI allows wrapping and calling JavaScript functions from within
client code written in Ur/Web. The JS code for this lives in:

  urweb_persona.js

This needs to be served by an external web server as Ur/Web doesn't provide
out of the box functionality to serve files. The Ur definitions for these
JS functions are in:

  personaFfi.urs

The core of the application is in:

  persona.ur
  persona.urs

With the glue that ties the project together in:

  persona.urp

urweb-persona's People

Contributors

doublec avatar sergei-mironov avatar

Watchers

James Cloos 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.