Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ported https://github.com/thinkphp/browserID-MooTools to jquery

  • Loading branch information...
commit 8829ecb9289628eb7dac59a093b5147a199d2cfa 1 parent 4459f6f
@altryne authored
View
18 Demos/browserID-yui-compressed.js
@@ -1,18 +0,0 @@
-/*
----
-description: This is a MooTools client library for the BrowserID Protocol
-
-authors:
-- Adrian Statescu (http://thinkphp.ro)
-
-license:
-- MIT-style license
-
-requires:
- core/1.4.5: '*'
-
-provides: BrowserID
-...
-*/
-
-var BrowserID=new Class({Implements:[Options,Events],options:{assertion:null,email:null,service:"login.php"},initialize:function(assertion,options){this.setOptions(options);this.options.assertion=assertion;this._verify_assertion();},_verify_assertion:function(){var request=new Request.JSON({url:"login.php",data:{assertion:this.options.assertion},onRequest:function(){if(window.console){console.log("Requesting...");}this.fireEvent("request");}.bind(this),onComplete:function(response){if(window.console){console.log("Completed...");}if(response.status&&response.status=="okay"){this.options.email=response.email;}this.fireEvent("complete",[response]);}.bind(this)}).send();}});
View
87 Demos/browserID.js
@@ -1,87 +0,0 @@
-var BrowserID = new Class({
-
- /**
- * Implements: Events and Options
- */
- Implements: [Options, Events],
-
- /**
- * options
- */
- options: {
-
- //the encoded assertion
- assertion: null,
- //user's email
- email: null,
- //proxy server to verify user's identity
- service: 'login.php'
- },
-
- /**
- * Constructor of class
- * @param assertion String - a string containing a signed claim that proves the user is who they say they are.
- * @param options Object - the options for this class.
- * @return None
- * @access public
- */
- initialize: function(assertion,options) {
-
- //set options
- this.setOptions(options)
-
- //holds the assertion
- this.options.assertion = assertion
-
- //got an assertion, now send it up to the server for verifying by using an AJAX Request POST
- //in this example we have a server running at 'login.php' which receives and verifies assertions
- this._verify_assertion()
- },
-
- /**
- * Make a Request AJAX POST to verify the user's identity
- * @param None
- * @return None
- * @access private
- */
- _verify_assertion: function() {
-
- //make a AJAX POST Request
- var request = new Request.JSON({
-
- //provided the service to verify
- url: 'login.php',
-
- //POST the param 'assertion'
- data: {assertion: this.options.assertion},
-
- onRequest: function() {
-
- //for debug
- if(window.console) console.log('Requesting...')
-
- //fire event onrequest
- this.fireEvent('request')
-
- }.bind(this),
-
- onComplete: function(response) {
-
- //for debug
- if(window.console) console.log('Completed...')
-
- //You must verify the assertion is authentic and extract the
- //user's email address from it.
- if(response.status && response.status == 'okay') {
-
- this.options.email = response.email
- }
-
- //fire event oncomplete
- this.fireEvent('complete',[response])
-
- }.bind(this)
-
- }).send()
- }
-})
View
97 Demos/index.html
@@ -1,72 +1,43 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
- <title>Plugin BrowserID MooTools</title>
- <style type="text/css">
- h1,h2,h3,body { font-family:'gill sans','dejavu sans',verdana,sans-serif; }
- h1 { font-family:menlo,'dejavu sans mono',monospace; }
- h1 {
- font-weight:bold;
- font-size:43px;
- letter-spacing: -1px;
- color:#000;
- margin-bottom:0;
- position:relative;
- }
- button{border:none;background:transparent;margin:0 2em;}
- </style>
- <script src="http://www.google.com/jsapi?key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
- <script type="text/javascript">google.load("mootools", "1.4");</script>
- <script src="https://browserid.org/include.js"></script>
- <script src="browserID-yui-compressed.js"></script>
- <script type="text/javascript">
+ <title>Demo for jquery-browserID plugin</title>
- window.addEvent('domready', function(){
- $('login').addEvent('click',function(){
- navigator.id.getVerifiedEmail(function(assertion){
- if(assertion) {
- //got an assertion, now send it up to the server for verification
- verify(assertion);
- } else {
- alert("I still don't know you");
- }
- });
- });
- });
+ <style type="text/css">
+ .browserid-login{
+ border: 0;
+ width: 185px;
+ height: 25px;
+ cursor: pointer;
+ background: url(https://developer.mozilla.org/files/3963/persona_sign_in_blue.png);
+ text-indent: -9999px;
+ }
+ .browserid-logout{
- function verify(assertion) {
+ }
+ </style>
+</head>
+<body>
- var browserid = new BrowserID(assertion, {
- onComplete: function(response){
- //if the server successfully verifies the assertion we
- //updating the UI by calling 'loggedIn()'
- if(response.status == 'okay') {
- loggedIn(response.email)
- //otherwise we handle the login failure
- } else {
- failure(response)
- }
- }
- })
- }
+<h1>Demo for jquery-browserID plugin</h1>
+<button id="login"></button>
- function loggedIn(email) {
- //do stuff with email
- var p = new Element('p').set('text','Logged In as: ' + email)
- $('login').parentNode.replaceChild(p,$('login'))
- }
+<!--put the scripts in the bottom like a good front ender would-->
- function failure(f) {
- //do stuff with failure
- alert('Failure reason: ' + f.reason)
- }
+<!-- Check for support for browserid in the browser, fallback to loading the polyfill -->
+<script>navigator.id || document.write('<script src="//browserid.org/include.js"><\/script>')</script>
+<!-- Load jquery from google's CDN + fallback - stolen from h5bp.com-->
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\/script>')</script>
+<!--Load our browserid.jquery.js file-->
+<script src="jquery.browserid.js"></script>
- </script>
-</head>
-<body>
-<h1>Plugin BrowserID MooTools</h1>
-<button id="login"><img src="https://browserid.org/i/sign_in_green.png" alt="sign in with browser ID"></button>
+<script>
+ $('#login').browserID({
+ onlogin : function(something){
+ console.log(something);
+ }
+ });
+</script>
</body>
-</html>
-
+</html>
View
86 Demos/jquery.browserid.js
@@ -0,0 +1,86 @@
+/**
+ * Description : This is a jQuery client library for the BrowserID Protocol.
+ * Created by Alex Wolkov (alexw.me) .
+ */
+
+(function ($) {
+ var options = {
+ assertion : null,
+ email : null,
+ login_button_class : 'browserid-login',
+ logout_button_class : 'browserid-logout',
+ onlogin : null,
+ onfail : null,
+ onlogout : null,
+ server : 'login.php'
+ }
+ var methods = {
+ init : function (settings) {
+ if(typeof settings === 'object'){
+ $.extend(options, settings);
+ }
+ this.addClass(options.login_button_class).on('click.login', _login);
+ },
+ getEmail:function () {
+ return options.email;
+ }
+ }
+ var _login = function () {
+ var $el = $(this);
+ navigator.id.get(function (assertion) {
+ if (assertion) {
+ options.assertion = assertion;
+ //got an assertion, now send it up to the server for verification
+ _verify_assertion.apply($el);
+ }else{
+ if(typeof options.onfail === 'function') {
+ options.onfail.apply(this);
+ }
+ }
+ });
+ }
+
+ var _logout = function () {
+ navigator.id.logout();
+ options.assertion = null;
+ options.email = null;
+ $(this).removeClass(options.logout_button_class).removeClass(options.login_button_class);
+
+ methods.init.apply($(this));
+ if(typeof options.onlogout === 'function') {
+ options.onlogout.apply(this);
+ }
+ }
+
+ var _verify_assertion = function(){
+ var $el = this;
+
+ $.getJSON(options.server, {assertion:options.assertion}, function (response) {
+ if(response.status && response.status == 'okay'){
+ options.email = response.email;
+ $el.removeClass(options.login_button_class).addClass('options.logout_button_class').text('Logout ('+ response.email +')');
+ $el.off('click.login').on('click.logout',_logout);
+
+ if(typeof options.onlogin === 'function') {
+ options.onlogin.apply(this);
+ }
+ }else if(response.status !== 'okay'){
+ if(typeof options.onfail === 'function') {
+ options.onfail.apply(response);
+ }
+ }
+ })
+ }
+
+ $.fn.browserID = function (method) {
+
+ // Method calling logic
+ if (methods[method]) {
+
+ return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
+ } else if (typeof method === 'object' || !method) {
+
+ return methods.init.apply(this, arguments);
+ }
+ }
+})(jQuery);
View
2  Demos/login.php
@@ -2,7 +2,7 @@
require_once('login.class.php');
- $browserID = new BrowserID($_SERVER['HTTP_HOST'], $_POST['assertion']);
+ $browserID = new BrowserID($_SERVER['HTTP_HOST'], $_REQUEST['assertion']);
if($browserID->verify_assertion()) {
View
38 Docs/BrowserID.md
@@ -1,43 +1,31 @@
Class: BrowserID {#BrowserID}
==============================
-This is a MooTools client library for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address.
+This is a jquery plugin for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address.
It aims to provide a secure way of proving your identity to servers across the internet, without having to create separate usernames and passwords each time.
Instead of a new username, it uses your email address as you identity which allows it to be descentralized since anyone can send you an
email verification message.
### Syntax:
-
- var browserID = new BrowserID(assertion, options);
-
+```
+ $('<your button element>').browserid([options]);
+```
### Arguments:
-- assertion `String` - a string containing a signed claim that proves the user is who they say they are.
-
- options `object` - The options for the BrowserID instance.
-### Events
-
-### onRequest
-
-* `function` Function to execute when you make a request.
-
-### Signature
-
- onRequest();
-
-### onComplete
-
-* `function` Function to execute when the request is completed.
-
-### Signature
-
- onComplete(response);
-
+####Example options :
+```
+ var options = {
+ onlogin : function(response){ ... },
+ onfail : function(response){ ... },
+ onlogout : function(response){ ... },
+ server : 'login.php' /* this is the verifier server url - attached in login.php */
+}
+```
### Arguments
- `object` The verifier will check that the assertion was meant for your website and is valid
returns => {status: 'okay','email': 'user@mozilla.com'},
otherwise returns {status: 'failure','reason': 'audience missmatch'},
-
View
81 README.md
@@ -1,7 +1,7 @@
BrowserID
=========
-This is a MooTools client library for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address.
+This is a jQuery client library for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address.
It aims to provide a secure way of proving your identity to servers across the internet, without having to create separate usernames and passwords each time.
Instead of a new username, it uses your email address as you identity which allows it to be descentralized since anyone can send you an
email verification message.
@@ -11,65 +11,37 @@ email verification message.
How to Use
----------
-Include the BrowserID include.js library in your site by adding the following script tag to your pages:
+###Include the BrowserID include.js library in your site by adding the following script tags to your pages:
+```
+<script>navigator.id || document.write('<script src="//browserid.org/include.js"><\/script>')</script>
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+<script src="jquery.browserid.js"></script>
+```
- <script src="https://browserid.org/include.js" type="text/javascript"></script>
- <script type="text/javascript" src="mootools.js"></script>
- <script type="text/javascript" src="browserID.js.js"></script>
+###Adding a login button:
-Adding a pretty button:
+```
+<button id="login">LOGIN</button>
+```
- #HTML
- <button id="login"><img src="https://browserid.org/i/sign_in_green.png" alt="sign in with browser ID"></button>
+###on DOM ready initiate
+```
+$('<your button element>').browserid([options]);
+```
-When DOM is ready:
+### Arguments:
- #JS
- window.addEvent('domready', function(){
+- options `object` - The options for the BrowserID instance.
- $('login').addEvent('click',function(){
- navigator.id.getVerifiedEmail(function(assertion){
- if(assertion) {
- //got an assertion, now send it up to the server for verification
- verify(assertion)
- } else {
- alert("I still don't know you")
- }
- })
- })
- })
-
-
- function verify(assertion) {
-
- var browserid = new BrowserID(assertion, {
-
- onComplete: function(response){
-
- //if the server successfully verifies the assertion we
- //updating the UI by calling 'loggedIn()'
- if(response.status == 'okay') {
-
- loggedIn(response.email)
-
- //otherwise we handle the login failure by calling 'failure()'
- } else {
- failure(response)
- }
- }
- })
- }
-
- function loggedIn(email) {
- //do stuff with email
- var p = new Element('p').set('text','Logged In as: ' + email)
- $('login').parentNode.replaceChild(p,$('login'))
- }
-
- function failure(f) {
- //do stuff with failure
- alert('Failure reason: ' + f.reason)
- }
+####Example options :
+```
+ var options = {
+ onlogin : function(response){ ... },
+ onfail : function(response){ ... },
+ onlogout : function(response){ ... },
+ server : 'login.php' /* this is the verifier server url - attached in login.php */
+}
+```
References:
@@ -79,3 +51,4 @@ References:
- http://identity.mozilla.com/post/7616727542/introducing-browserid-a-better-way-to-sign-in
- http://identity.mozilla.com/post/17207734786/id-provider-support-now-live-on-browserid
- https://github.com/mozilla/browserid/wiki
+- https://github.com/thinkphp/browserID-MooTools
View
18 Source/browserID-yui-compressed.js
@@ -1,18 +0,0 @@
-/*
----
-description: This is a MooTools client library for the BrowserID Protocol
-
-authors:
-- Adrian Statescu (http://thinkphp.ro)
-
-license:
-- MIT-style license
-
-requires:
- core/1.4.5: '*'
-
-provides: BrowserID
-...
-*/
-
-var BrowserID=new Class({Implements:[Options,Events],options:{assertion:null,email:null,service:"login.php"},initialize:function(assertion,options){this.setOptions(options);this.options.assertion=assertion;this._verify_assertion();},_verify_assertion:function(){var request=new Request.JSON({url:"login.php",data:{assertion:this.options.assertion},onRequest:function(){if(window.console){console.log("Requesting...");}this.fireEvent("request");}.bind(this),onComplete:function(response){if(window.console){console.log("Completed...");}if(response.status&&response.status=="okay"){this.options.email=response.email;}this.fireEvent("complete",[response]);}.bind(this)}).send();}});
View
104 Source/browserID.js
@@ -1,104 +0,0 @@
-/*
----
-description: This is a MooTools client library for the BrowserID Protocol.
-
-authors:
-- Adrian Statescu (http://thinkphp.ro)
-
-license:
-- MIT-style license
-
-requires:
- core/1.4.5: '*'
-
-provides: BrowserID
-...
-*/
-
-var BrowserID = new Class({
-
- /**
- * Implements: Events and Options
- */
- Implements: [Options, Events],
-
- /**
- * options
- */
- options: {
-
- //the encoded assertion
- assertion: null,
- //user's email
- email: null,
- //proxy server to verify user's identity
- service: 'login.php'
- },
-
- /**
- * Constructor of class
- * @param assertion String - a string containing a signed claim that proves the user is who they say they are.
- * @param options Object - the options for this class.
- * @return None
- * @access public
- */
- initialize: function(assertion,options) {
-
- //set options
- this.setOptions(options)
-
- //holds the assertion
- this.options.assertion = assertion
-
- //got an assertion, now send it up to the server for verifying by using an AJAX Request POST
- //in this example we have a server running at 'login.php' which receives and verifies assertions
- this._verify_assertion()
- },
-
- /**
- * Make a Request AJAX POST to verify the user's identity
- * @param None
- * @return None
- * @access private
- */
- _verify_assertion: function() {
-
- //make a AJAX POST Request
- var request = new Request.JSON({
-
- //provided the service to verify
- url: 'login.php',
-
- //POST the param 'assertion'
- data: {assertion: this.options.assertion},
-
- onRequest: function() {
-
- //for debug
- if(window.console) console.log('Requesting...')
-
- //fire event onrequest
- this.fireEvent('request')
-
- }.bind(this),
-
- onComplete: function(response) {
-
- //for debug
- if(window.console) console.log('Completed...')
-
- //You must verify the assertion is authentic and extract the
- //user's email address from it.
- if(response.status && response.status == 'okay') {
-
- this.options.email = response.email
- }
-
- //fire event oncomplete
- this.fireEvent('complete',[response])
-
- }.bind(this)
-
- }).send()
- }
-})
View
1  Source/jquery.browserid-min.js
@@ -0,0 +1 @@
+(function(e){var t={assertion:null,email:null,login_button_class:"browserid-login",logout_button_class:"browserid-logout",onlogin:null,onfail:null,onlogout:null,server:"login.php"},n={init:function(n){typeof n=="object"&&e.extend(t,n);this.addClass(t.login_button_class).on("click.login",r)},getEmail:function(){return t.email}},r=function(){var n=e(this);navigator.id.get(function(e){if(e){t.assertion=e;s.apply(n)}else typeof t.onfail=="function"&&t.onfail.apply(this)})},i=function(){navigator.id.logout();t.assertion=null;t.email=null;e(this).removeClass(t.logout_button_class).removeClass(t.login_button_class);n.init.apply(e(this));typeof t.onlogout=="function"&&t.onlogout.apply(this)},s=function(){var n=this;e.getJSON(t.server,{assertion:t.assertion},function(e){if(e.status&&e.status=="okay"){t.email=e.email;n.removeClass(t.login_button_class).addClass("options.logout_button_class").text("Logout ("+e.email+")");n.off("click.login").on("click.logout",i);typeof t.onlogin=="function"&&t.onlogin.apply(this)}else e.status!=="okay"&&typeof t.onfail=="function"&&t.onfail.apply(e)})};e.fn.browserID=function(e){if(n[e])return n[e].apply(this,Array.prototype.slice.call(arguments,1));if(typeof e=="object"||!e)return n.init.apply(this,arguments)}})(jQuery);
View
86 Source/jquery.browserid.js
@@ -0,0 +1,86 @@
+/**
+ * Description : This is a jQuery client library for the BrowserID Protocol.
+ * Created by Alex Wolkov (alexw.me) .
+ */
+
+(function ($) {
+ var options = {
+ assertion : null,
+ email : null,
+ login_button_class : 'browserid-login',
+ logout_button_class : 'browserid-logout',
+ onlogin : null,
+ onfail : null,
+ onlogout : null,
+ server : 'login.php'
+ }
+ var methods = {
+ init : function (settings) {
+ if(typeof settings === 'object'){
+ $.extend(options, settings);
+ }
+ this.addClass(options.login_button_class).on('click.login', _login);
+ },
+ getEmail:function () {
+ return options.email;
+ }
+ }
+ var _login = function () {
+ var $el = $(this);
+ navigator.id.get(function (assertion) {
+ if (assertion) {
+ options.assertion = assertion;
+ //got an assertion, now send it up to the server for verification
+ _verify_assertion.apply($el);
+ }else{
+ if(typeof options.onfail === 'function') {
+ options.onfail.apply(this);
+ }
+ }
+ });
+ }
+
+ var _logout = function () {
+ navigator.id.logout();
+ options.assertion = null;
+ options.email = null;
+ $(this).removeClass(options.logout_button_class).removeClass(options.login_button_class);
+
+ methods.init.apply($(this));
+ if(typeof options.onlogout === 'function') {
+ options.onlogout.apply(this);
+ }
+ }
+
+ var _verify_assertion = function(){
+ var $el = this;
+
+ $.getJSON(options.server, {assertion:options.assertion}, function (response) {
+ if(response.status && response.status == 'okay'){
+ options.email = response.email;
+ $el.removeClass(options.login_button_class).addClass('options.logout_button_class').text('Logout ('+ response.email +')');
+ $el.off('click.login').on('click.logout',_logout);
+
+ if(typeof options.onlogin === 'function') {
+ options.onlogin.apply(this);
+ }
+ }else if(response.status !== 'okay'){
+ if(typeof options.onfail === 'function') {
+ options.onfail.apply(response);
+ }
+ }
+ })
+ }
+
+ $.fn.browserID = function (method) {
+
+ // Method calling logic
+ if (methods[method]) {
+
+ return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
+ } else if (typeof method === 'object' || !method) {
+
+ return methods.init.apply(this, arguments);
+ }
+ }
+})(jQuery);
View
2  Source/login.php
@@ -2,7 +2,7 @@
require_once('login.class.php');
- $browserID = new BrowserID($_SERVER['HTTP_HOST'], $_POST['assertion']);
+ $browserID = new BrowserID($_SERVER['HTTP_HOST'], $_REQUEST['assertion']);
if($browserID->verify_assertion()) {
View
7 package.yml
@@ -1,7 +0,0 @@
-name: browserID
-author: thinkphp
-current: v1.0
-category: Utilities
-tags: [browserID,mozilla,authentication,security,identity]
-docs: https://github.com/thinkphp/browserID-MooTools/blob/master/Docs/BrowserID.md
-demo: http://thinkphp.ro/apps/js-hacks/browserID-MooTools/Demos/
Please sign in to comment.
Something went wrong with that request. Please try again.