Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit 7eef255

Browse files
Merge pull request #6 from DarkGhostHunter/master
2.0
2 parents 7ef7f8e + d63b9ee commit 7eef255

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2641
-182
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
composer.lock
33
docs
44
vendor
5-
coverage
5+
coverage
6+
.idea

README.md

Lines changed: 177 additions & 48 deletions
Large diffs are not rendered by default.

config/larapass.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,17 @@
140140
*/
141141

142142
'fallback' => true,
143+
144+
/*
145+
|--------------------------------------------------------------------------
146+
| Device Confirmation
147+
|--------------------------------------------------------------------------
148+
|
149+
| If you're using the "webauthn.confirm" middleware in your routes you may
150+
| want to adjust the time the confirmation is remembered in the browser.
151+
| This is measured in seconds, but it can be overridden in the route.
152+
|
153+
*/
154+
155+
'confirm_timeout' => 10800, // 3 hours
143156
];

database/migrations/2020_04_02_000000_create_web_authn_credentials_table.php renamed to database/migrations/2020_04_02_000000_create_web_authn_tables.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
66
use DarkGhostHunter\Larapass\Eloquent\WebAuthnCredential;
77

8-
class CreateWebAuthnCredentialsTable extends Migration
8+
class CreateWebAuthnTables extends Migration
99
{
1010
/**
1111
* Run the migrations.
@@ -39,6 +39,12 @@ public function up()
3939

4040
$table->primary(['id', 'user_id']);
4141
});
42+
43+
Schema::create('web_authn_recoveries', function (Blueprint $table) {
44+
$table->string('email')->index();
45+
$table->string('token');
46+
$table->timestamp('created_at')->nullable();
47+
});
4248
}
4349

4450
/**
@@ -49,5 +55,6 @@ public function up()
4955
public function down()
5056
{
5157
Schema::dropIfExists('web_authn_authentications');
58+
Schema::dropIfExists('web_authn_recoveries');
5259
}
5360
}

resources/js/larapass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class Larapass
258258
*
259259
* @param data {{string}}
260260
* @param headers {{string}}
261-
* @returns Promise<any>
261+
* @returns Promise<JSON|ReadableStream>
262262
*/
263263
async login(data = {}, headers = {})
264264
{
@@ -279,7 +279,7 @@ class Larapass
279279
*
280280
* @param data {{string}}
281281
* @param headers {{string}}
282-
* @returns Promise<any>
282+
* @returns Promise<JSON|ReadableStream>
283283
*/
284284
async register(data = {}, headers = {})
285285
{

resources/lang/en/confirm.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'title' => 'Please confirm with your device before continuing',
5+
'button' => 'Confirm'
6+
];

resources/lang/en/recovery.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
return [
4+
'title' => 'Account recovery',
5+
6+
'description' => 'If you can\'t login with your device, you can register another by opening an email there.',
7+
'details' => 'Ensure you open the email on a device you fully own.',
8+
9+
'instructions' => 'Press the button to use this device for your account and follow your the instructions.',
10+
'unique' => 'Disable all others devices except this.',
11+
12+
'button' => [
13+
'send' => 'Send account recovery',
14+
'register' => 'Register this device',
15+
],
16+
17+
'sent' => 'If the email is correct, you should receive an email with a recovery link shortly.',
18+
'attached' => 'A new device has been attached to your account to authenticate.',
19+
'user' => 'We can\'t find a user with that email address.',
20+
'token' => 'The token is invalid or has expired.',
21+
'throttled' => 'Please wait before retrying.',
22+
23+
'failed' => 'The recovery failed. Try again.',
24+
];

resources/views/confirm.blade.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@extends('larapass::layout')
2+
3+
@section('title', __('Authenticator confirmation'))
4+
5+
@section('body')
6+
<form id="form">
7+
<h2 class="card-title h5 text-center">{{ __('Please confirm with your device before continuing') }}</h2>
8+
<hr>
9+
<div class="text-center">
10+
<button type="submit" class="btn btn-primary btn-lg">
11+
{{ __('Confirm') }}
12+
</button>
13+
</div>
14+
</form>
15+
@endsection
16+
17+
@push('scripts')
18+
<script src="{{ asset('vendor/larapass/js/larapass.js') }}"></script>
19+
<script>
20+
const larapass = new Larapass({
21+
login: '/webauthn/confirm',
22+
loginOptions: '/webauthn/confirm/options'
23+
});
24+
25+
document.getElementById('form').addEventListener('submit', function (event) {
26+
event.preventDefault()
27+
28+
larapass.login()
29+
.then(response => window.location.replace(response.redirectTo))
30+
.catch(response => {
31+
alert('{{ __('Confirmation unsuccessful, try again!') }}')
32+
console.error('Confirmation unsuccessful', response);
33+
})
34+
})
35+
</script>
36+
@endpush

resources/views/layout.blade.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!doctype html>
2+
<html lang="{{ config('app.locale') }}">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
9+
<title>@yield('title')</title>
10+
<style>
11+
#box-container {
12+
min-height: 100vh;
13+
}
14+
#box {
15+
margin-bottom: 6rem;
16+
}
17+
.cool-shadow {
18+
box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.1),
19+
0 6.7px 5.3px rgba(0, 0, 0, 0.072),
20+
0 12.5px 10px rgba(0, 0, 0, 0.06),
21+
0 22.3px 17.9px rgba(0, 0, 0, 0.05),
22+
0 41.8px 33.4px rgba(0, 0, 0, 0.04),
23+
0 100px 80px rgba(0, 0, 0, 0.028);
24+
}
25+
</style>
26+
</head>
27+
<body class="bg-light">
28+
<div class="container">
29+
<div id="box-container" class="row justify-content-center align-items-center">
30+
<div id="form-container" class="col-lg-6 col-md-8 col-sm-10 col-12">
31+
<div id="box" class="card border-0 cool-shadow">
32+
<section class="card-body">
33+
@yield('body')
34+
</section>
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
@stack('scripts')
40+
</body>
41+
</html>

resources/views/lost.blade.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@extends('larapass::layout')
2+
3+
@section('title', trans('larapass::recovery.title'))
4+
5+
@section('body')
6+
<form id="form" action="{{ route('webauthn.lost.send') }}" method="post">
7+
@csrf
8+
<h2 class="card-title h5 text-center">{{ trans('larapass::recovery.title') }}</h2>
9+
<hr>
10+
<p>{{ trans('larapass::recovery.description') }}</p>
11+
@if($errors->any())
12+
<div class="alert alert-danger small">
13+
<ul>
14+
@foreach ($errors->all() as $error)
15+
<li>{{ $error }}</li>
16+
@endforeach
17+
</ul>
18+
</div>
19+
@elseif(session('status'))
20+
<div class="alert alert-success small">
21+
{{ session('status') }}
22+
</div>
23+
@endif
24+
<div class="form-group pb-3">
25+
<label for="email">Email</label>
26+
<input id="email" type="email" name="email" class="form-control" placeholder="john.doe@mail.com" required>
27+
<small class="form-text text-muted">{{ trans('larapass::recovery.details') }}</small>
28+
</div>
29+
<div class="text-center">
30+
<button type="submit" class="btn btn-primary btn-lg">{{ trans('larapass::recovery.button.send') }}</button>
31+
</div>
32+
</form>
33+
@endsection

0 commit comments

Comments
 (0)