Created
April 3, 2012 01:52
-
-
Save tiye/2288709 to your computer and use it in GitHub Desktop.
A Node demo to run browserid with `https` module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = document.getElementById 'login' | |
ll = (v...) -> | |
console.log v | |
socket = io.connect window.location.hostname | |
socket.on 'ready', (data) -> | |
ll data | |
image.onclick = -> | |
navigator.id.get (assertion) -> | |
ll 'got, sending' | |
socket.emit 'assertion', assertion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Attention!! this shoule be compiled to `html` before running | |
// Tested on Fedora, Chrome | |
html | |
head | |
script(type='text/coffeescript') | |
@@@ | |
script(src="/socket.io/socket.io.js") | |
script(src='https://browserid.org/include.js') | |
script(src='http://docview.cnodejs.net/libs/coffee-script.js?js') | |
body | |
image#login(src='https://browserid.org/i/sign_in_red.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run with `$ coffee server.coffee` | |
# tested on Fedora, Chrome | |
# can get right response now.. might be still buggy though | |
# http://stackoverflow.com/questions/9979588/node-js-throw-e-process-nexttick-error-while-trying-browserid/9979847 | |
ll = console.log | |
fs = require 'fs' | |
page = fs.readFileSync 'page.html', 'utf-8' | |
query = require 'querystring' | |
client = fs.readFileSync 'client.coffee', 'utf-8' | |
page = page.replace '@@@', client | |
handler = (req, res) -> | |
res.writeHead 200, 'Content-Type': 'text/html' | |
res.end page | |
http = require 'http' | |
https = require 'https' | |
app = http.createServer handler | |
app.listen 8000 | |
io = (require 'socket.io').listen app | |
io.set 'log level', 1 | |
io.sockets.on 'connection', (socket) -> | |
socket.emit 'ready', 'go' | |
socket.on 'assertion', (data) -> | |
msg = query.stringify | |
assertion: data | |
audience: 'localhost:8000' | |
options = | |
host: 'browserid.org' | |
port: 443 | |
path: '/verify' | |
method: 'POST' | |
headers: | |
'Content-Type': 'application/x-www-form-urlencoded' | |
'Content-Length': msg.length | |
request = https.request options, (response) -> | |
str = '' | |
ll 'prepare' | |
response.on 'data', (chunk) -> | |
str += chunk | |
response.on 'end', -> | |
ll str | |
request.write msg | |
request.end() | |
request.on 'error', (data) -> | |
ll data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment