Skip to content

Commit

Permalink
Replace chrome-extension with u2f-api.js from Google's github. (#30)
Browse files Browse the repository at this point in the history
Also, use thin to serve the example over https.

u2f-api.js comes from https://github.com/google/u2f-ref-code/tree/master/u2f-gae-demo/war/js/u2f-api.js
  • Loading branch information
alokmenghrajani authored and wallin committed Apr 4, 2017
1 parent 54cf4ba commit 921aeb7
Show file tree
Hide file tree
Showing 9 changed files with 778 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
u2f (0.2.1)
u2f (1.0.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -82,4 +82,4 @@ DEPENDENCIES
u2f!

BUNDLED WITH
1.11.0
1.12.3
3 changes: 3 additions & 0 deletions example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ gem 'dm-core'
# Padrino Stable Gem
gem 'padrino', '0.12.4'

# To enable https
gem 'thin'

gem 'u2f'#, path: '../.'
10 changes: 10 additions & 0 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GEM
bcrypt (3.1.9)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
daemons (1.2.4)
data_objects (0.10.14)
addressable (~> 2.1)
dm-aggregates (1.2.0)
Expand Down Expand Up @@ -41,6 +42,7 @@ GEM
dm-core (~> 1.2.0)
do_sqlite3 (0.10.14)
data_objects (= 0.10.14)
eventmachine (1.2.3)
fastercsv (1.5.5)
haml (4.0.5)
tilt
Expand Down Expand Up @@ -100,6 +102,10 @@ GEM
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
stringex (1.5.1)
thin (1.7.0)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
Expand Down Expand Up @@ -128,4 +134,8 @@ DEPENDENCIES
haml
padrino (= 0.12.4)
rake
thin
u2f

BUNDLED WITH
1.12.3
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```bash
bundle install
padrino rake db:migrate
padrino start
thin start --ssl --ssl-disable-verify
```
14 changes: 7 additions & 7 deletions example/app/controllers/registrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
post :index do
response = U2F::RegisterResponse.load_from_json(params[:response])

reg = begin
u2f.register!(session[:challenges], response)
begin
reg = u2f.register!(session[:challenges], response)

Registration.create!(certificate: reg.certificate,
key_handle: reg.key_handle,
public_key: reg.public_key,
counter: reg.counter)
rescue U2F::Error => e
@error_message = "Unable to register: #{e.class.name}"
ensure
session.delete(:challenges)
end

Registration.create!(certificate: reg.certificate,
key_handle: reg.key_handle,
public_key: reg.public_key,
counter: reg.counter)

render 'authentications/show'
end
end
4 changes: 3 additions & 1 deletion example/app/views/authentications/new.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
$error.style.display = 'block';
$error.innerHTML = errorMap[code];
};
var appId = signRequests[0].appId
var challenge = signRequests[0].challenge

u2f.sign(signRequests, function(signResponse) {
u2f.sign(appId, challenge, signRequests, function(signResponse) {
var form, reg;

if (signResponse.errorCode) {
Expand Down
4 changes: 2 additions & 2 deletions example/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<%= stylesheet_link_tag '//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' %>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
<style type="text/css">
body { font-family: 'Source Sans Pro', sans-serif; }
</style>
<script src="chrome-extension://pfboblefjcgdjicmnffhdgionmgcdmne/u2f-api.js"></script>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'u2f-api' %>
</head>
<body>
<!--[if lt IE 7]>
Expand Down
3 changes: 2 additions & 1 deletion example/app/views/registrations/new.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
$error.style.display = 'block';
$error.innerHTML = errorMap[code];
};
var appId = registerRequests[0].appId

u2f.register(registerRequests, signRequests, function(registerResponse) {
u2f.register(appId, registerRequests, signRequests, function(registerResponse) {
var form, reg;

if (registerResponse.errorCode) {
Expand Down
Loading

0 comments on commit 921aeb7

Please sign in to comment.