Plack::Middleware::Auth::BrowserID - Plack Middleware to integrate with Mozilla Persona (Auth by email)
version 0.0.7
#.. on PSGI file use Plack::Builder; use Plack::Session; ##.. builder { enable 'Session', store => 'File'; mount '/auth' => builder { enable 'Auth::BrowserID', audience => 'http://localhost:8082/'; }; mount '/' => $app; };
Mozilla Persona is a secure solutions, to identify users based on email address.
"Simple, privacy-sensitive single sign-in: let your users sign into your website with their email address, and free yourself from password management."
Some Javascript code is needed in the client side. First include the dependencies:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script> <script src="https://login.persona.org/include.js"></script>"
Setup the watch with email and url's for login and logout (as defined in the PSGI "mount '/auth'"):
email = $.cookie('email') || null; navigator.id.watch({ loggedInUser: email, onlogin: function(assertion) { return $.post('/auth/signin', { assertion: assertion }, function(data) { return window.location.reload(); }); }, onlogout: function() { return window.location = '/auth/signout'; } });
And map the events in the DOM with the watch from Mozilla:
var signinLink = document.getElementById('signin'); if (signinLink) { signinLink.onclick = function() { navigator.id.request(); }; } var signoutLink = document.getElementById('signout'); if (signoutLink) { signoutLink.onclick = function() { navigator.id.logout(); }; }
Please look for the example and read the Mozilla Persona info on MDN.
In the web application get the Plack::Session (example):
use Dancer2; use Plack::Session; get '/' => sub { my $session = Plack::Session->new( shift->env ); 'Hi! do you wanna dance? ' . $session->get('email'); };
See the functional example on the examples folder.
plackup -s Starman -r -p 8082 -E development -I lib example/app.psgi
Plack::Middleware::Session LWP::Protocol::https Net::BrowserID::Verify
João Bolila <bolila@cpan.org>
This software is copyright (c) 2013 by J. Bolila.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::Auth::BrowserID, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Auth::BrowserID
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Auth::BrowserID
For more information on module installation, please visit the detailed CPAN module installation guide.