Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial migration, starting to write the BrowserID stuff.

  • Loading branch information...
commit 78cedec05845b3d59f346461701c4c6142aa2c67 1 parent 7d67510
@brianloveswords brianloveswords authored
View
12 .gitignore
@@ -1,7 +1,5 @@
-*.pyc
-*.db
-/backpack/settings_local.py
-/log.txt
-/pip-log.txt
-/settings_local.py
-/src/
+/var/*
+!/var/.gitkeep
+/node_modules
+*log
+notes
View
62 app.js
@@ -0,0 +1,62 @@
+var express = require('express'),
+ logger = require('winston'),
+ ejs = require('ejs'),
+ https = require('https'),
+ querystring = require('querystring');
+
+// setup logging
+// logger.add(logger.transports.File, { filename: 'development.log' });
+
+var app = express.createServer();
+app.set('view engine', 'ejs');
+
+// middleware
+app.use(express.bodyParser());
+
+// check if logged in, render login page if not.
+app.get('/', function(req, res) {
+ res.render('index');
+})
+
+// sign in with browser id
+app.post('/sign-in', function(req, res) {
+ // throw out 403 if we can't find assertion
+ if (!req.body['assertion']) {
+ res.status(403)
+ res.send('forbidden');
+ return;
+ }
+ var params = querystring.stringify({
+ assertion: req.body['assertion'],
+ audience: 'hub.local'
+ });
+ var options = {
+ host: 'browserid.org',
+ port: '443',
+ path: '/verify',
+ method: 'POST',
+ headers: {
+ 'Content-Length': params.length
+ }
+ };
+
+ var verifier = https.request(options, function(res) {
+ var body = '';
+ logger.info('SENDING: ' + params);
+ logger.info('STATUS: ' + res.statusCode);
+ logger.info('HEADERS: ' + JSON.stringify(res.headers));
+ res.on('data', function(chunk){ body += chunk; })
+ res.on('end', function(){
+ logger.info('BODY: ' + body);
+ console.dir(res);
+ })
+ });
+ verifier.on('error', function(e) {
+ logger.warn('problem with assertion verification request:' + e.message);
+ });
+ verifier.end(params);
+ res.send('yeaaaaaa');
+})
+
+app.listen(80);
+logger.info('READY PLAYER ONE');
View
61 lib/secrets.js
@@ -0,0 +1,61 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla BrowserID.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+const
+path = require('path'),
+fs = require('fs');
+
+exports.generate = function(chars) {
+ var str = "";
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ for (var i=0; i < chars; i++) {
+ str += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
+ }
+ return str;
+}
+
+exports.hydrateSecret = function(name, dir) {
+ var p = path.join(dir, name + ".sekret");
+ var fileExists = false;
+ var secret = undefined;
+
+ try{ secret = fs.readFileSync(p).toString(); } catch(e) {};
+
+ if (secret === undefined) {
+ secret = exports.generate(128);
+ fs.writeFileSync(p, secret);
+ }
+ return secret;
+};
View
18 package.json
@@ -0,0 +1,18 @@
+{
+ "name": "badgehub"
+ , "description": "https://wiki.mozilla.org/Badges"
+ , "version": "0.5.0"
+ , "private": true
+ , "dependencies": {
+ "express": "2.4.x"
+ , "express-csrf": "0.3.x"
+ , "uglify-js": "1.0.x"
+ , "winston": "0.3.x"
+ , "mongoose": "1.8.x"
+ , "ejs": "0.4.x"
+ }
+ , "devDependencies": {
+ "vows": "0.5.x"
+ }
+ , "engine": "node 0.4.x"
+}
View
17 templates/base.html
@@ -1,17 +0,0 @@
-<!doctype html public "☄">
-<html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
-
- <title dir="ltr">Badge Backpack{% block title %} | Welcome{% endblock %}</title>
-
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="https://browserid.org/include.js" type="text/javascript"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <link href="/media/css/style.css" rel="stylesheet" type="text/css" media="all">
- </head>
- <body>
- {% block content %}{% endblock %}
- </body>
-</html>
View
4 templates/index.html
@@ -1,4 +0,0 @@
-{% extends "base.html" %}
-{% block content %}
- <p>Where all your dreams can come true</p>
-{% endblock %}
View
9 test.js
@@ -0,0 +1,9 @@
+var request = require('request');
+
+request('http://browserid.org', function(error, response, body) {
+ if (!error && response.statusCode == 200) {
+ console.log(body);
+ }
+})
+
+
View
0  var/.gitkeep
No changes.
View
0  templates/500.html → views/500.ejs
File renamed without changes
View
21 views/index.ejs
@@ -0,0 +1,21 @@
+<h1>Sign in with BrowserID</h1>
+<a href='#' id='sign-in'><img src='https://browserid.org/i/sign_in_green.png'></a>
+
+<form class='sign-in' method='POST' action='/sign-in'>
+ <input id='browserid-assertion' name='assertion' type='hidden'>
+</form>
+
+<script type='text/javascript'>
+ var login = function(){
+ navigator.id.getVerifiedEmail(function(assertion) {
+ if (assertion) {
+ $('#browserid-assertion').val(assertion);
+ $('form.sign-in').trigger('submit');
+ } else {
+ // pass
+ }
+ })
+ }
+
+ $('#sign-in').bind('click', login);
+</script>
View
15 views/layout.ejs
@@ -0,0 +1,15 @@
+<!doctype html public "oh sup">
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="/media/css/style.css" type="text/css" media="all">
+ <title dir="ltr">Badge Backpack | Welcome</title>
+ <script type="text/javascript" src="https://browserid.org/include.js"></script>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+ </head>
+ <body>
+ <%- body %>
+ </body>
+</html>
View
1  views/login.ejs
@@ -0,0 +1 @@
+h1 Sign in with browserid you fucken cretin!
Please sign in to comment.
Something went wrong with that request. Please try again.