Git Product home page Git Product logo

slouchin's Introduction

slouchin

Cookie-based authentication example in PHP for CouchDB.

Setup

Pre-reqs

  1. Install and run CouchDB (on port 5984); 0. Setup an admin account for your CouchDB (if you haven't already)
  2. Copy the contents of the 'src' folder of the Sag project fork by BigBlueHat into a 'Sag' folder inside this directory. The fork includes the cookie authentication code.
  3. Create a "slouchin_test" database
  4. Set both Admin and Reader permissions on that database to the admin account you created above (see "Security..." for that DB in Futon)
  5. Load up the slouchin index.html file
  6. Login with the admin account you just created

After login, you'll be taken to a "private.php" page which just outputs some text (think the page from your old app).

Next, follow the link to the "storedoc.php" page. At that page, a CouchDB doc will be generated and the result of the PUT operation will be output.

storedoc.php uses the CouchDB AuthSession cookie it got during login to re-authenticate (cookie style) your session and let you, the admin, save the doc. In this slouchin example, the AuthSession is stored as the PHP session ID, but it could be stored within $_SESSION if you wanted to use PHP's auto-generated session ID (or your own, or whatever).

Currently (because this is just a simple demo), if you delete the cookie, and try and access the storedoc.php file again, you should get an unauthorized notice rather than being redirected to the login page.

Summary

Using this simple example, you should be able to setup CouchDB as your user/profile management system (with a bit more work), use CouchDB for session expiration, and do whatever else you might want to with CouchDB thanks to Sag.

License

Apache License 2.0

Special Thanks to...

Sag: PHP on CouchDB

slouchin's People

Stargazers

Barry Jones avatar BigBlueHat avatar

Watchers

James Cloos avatar  avatar

slouchin's Issues

Undefined property with cookie

Getting the following error when trying to login:

Notice: Undefined property: stdClass::$cookies in /../Sag/Sag.php on line 198

resulting in if ($res->body->ok) on slouchin.php returning false

Any thoughts?

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.