generate qr code locally
This commit is contained in:
parent
1da85c96cf
commit
a1d52af0ba
|
@ -6789,6 +6789,11 @@
|
||||||
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
|
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"qrious": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/qrious/-/qrious-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-xWPJIrK1zu5Ypn898fBp8RHkT/9ibquV2Kv24S/JY9VYEhMBMKur1gHVsOiNUh7PHP9uCgejjpZUHUIXXKoU/g=="
|
||||||
|
},
|
||||||
"qs": {
|
"qs": {
|
||||||
"version": "6.3.2",
|
"version": "6.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz",
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
"node-forge": "0.7.1",
|
"node-forge": "0.7.1",
|
||||||
"papaparse": "4.3.5",
|
"papaparse": "4.3.5",
|
||||||
"popper.js": "1.14.3",
|
"popper.js": "1.14.3",
|
||||||
|
"qrious": "4.0.2",
|
||||||
"rxjs": "5.5.6",
|
"rxjs": "5.5.6",
|
||||||
"sweetalert": "2.1.0",
|
"sweetalert": "2.1.0",
|
||||||
"tldjs": "2.0.0",
|
"tldjs": "2.0.0",
|
||||||
|
|
|
@ -49,8 +49,7 @@
|
||||||
</p>
|
</p>
|
||||||
<hr *ngIf="enabled">
|
<hr *ngIf="enabled">
|
||||||
<p class="text-center" [ngClass]="{'mb-0': enabled}">
|
<p class="text-center" [ngClass]="{'mb-0': enabled}">
|
||||||
<img [src]="qr" width="160" height="160" alt="">
|
<canvas id="qr"></canvas><br>
|
||||||
<br>
|
|
||||||
<code title="{{'key' | i18n}}">{{key}}</code>
|
<code title="{{'key' | i18n}}">{{key}}</code>
|
||||||
</p>
|
</p>
|
||||||
<ng-container *ngIf="!enabled">
|
<ng-container *ngIf="!enabled">
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { Component } from '@angular/core';
|
import {
|
||||||
|
Component,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
import { ToasterService } from 'angular2-toaster';
|
||||||
import { Angulartics2 } from 'angulartics2';
|
import { Angulartics2 } from 'angulartics2';
|
||||||
|
@ -19,17 +23,29 @@ import { TwoFactorBaseComponent } from './two-factor-base.component';
|
||||||
selector: 'app-two-factor-authenticator',
|
selector: 'app-two-factor-authenticator',
|
||||||
templateUrl: 'two-factor-authenticator.component.html',
|
templateUrl: 'two-factor-authenticator.component.html',
|
||||||
})
|
})
|
||||||
export class TwoFactorAuthenticatorComponent extends TwoFactorBaseComponent {
|
export class TwoFactorAuthenticatorComponent extends TwoFactorBaseComponent implements OnInit, OnDestroy {
|
||||||
key: string;
|
key: string;
|
||||||
qr: string;
|
|
||||||
token: string;
|
token: string;
|
||||||
formPromise: Promise<any>;
|
formPromise: Promise<any>;
|
||||||
|
|
||||||
|
private qrScript: HTMLScriptElement;
|
||||||
|
|
||||||
constructor(apiService: ApiService, i18nService: I18nService,
|
constructor(apiService: ApiService, i18nService: I18nService,
|
||||||
analytics: Angulartics2, toasterService: ToasterService,
|
analytics: Angulartics2, toasterService: ToasterService,
|
||||||
private userService: UserService, platformUtilsService: PlatformUtilsService) {
|
private userService: UserService, platformUtilsService: PlatformUtilsService) {
|
||||||
super(apiService, i18nService, analytics, toasterService, platformUtilsService,
|
super(apiService, i18nService, analytics, toasterService, platformUtilsService,
|
||||||
TwoFactorProviderType.Authenticator);
|
TwoFactorProviderType.Authenticator);
|
||||||
|
this.qrScript = window.document.createElement('script');
|
||||||
|
this.qrScript.src = 'scripts/qrious.min.js';
|
||||||
|
this.qrScript.async = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
window.document.body.appendChild(this.qrScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
window.document.body.removeChild(this.qrScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
auth(authResponse: any) {
|
auth(authResponse: any) {
|
||||||
|
@ -62,9 +78,14 @@ export class TwoFactorAuthenticatorComponent extends TwoFactorBaseComponent {
|
||||||
this.token = null;
|
this.token = null;
|
||||||
this.enabled = response.enabled;
|
this.enabled = response.enabled;
|
||||||
this.key = response.key;
|
this.key = response.key;
|
||||||
this.qr = 'https://chart.googleapis.com/chart?chs=160x160&chld=L|0&cht=qr&chl=otpauth://totp/' +
|
const email = await this.userService.getEmail();
|
||||||
'Bitwarden:' + encodeURIComponent(await this.userService.getEmail()) +
|
window.setTimeout(() => {
|
||||||
'%3Fsecret=' + encodeURIComponent(this.key) +
|
const qr = new (window as any).QRious({
|
||||||
'%26issuer=Bitwarden';
|
element: document.getElementById('qr'),
|
||||||
|
value: 'otpauth://totp/Bitwarden:' + encodeURIComponent(email) +
|
||||||
|
'?secret=' + encodeURIComponent(this.key) + '&issuer=Bitwarden',
|
||||||
|
size: 160,
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,7 @@ const plugins = [
|
||||||
{ from: './src/images', to: 'images' },
|
{ from: './src/images', to: 'images' },
|
||||||
{ from: './src/locales', to: 'locales' },
|
{ from: './src/locales', to: 'locales' },
|
||||||
{ from: './src/scripts', to: 'scripts' },
|
{ from: './src/scripts', to: 'scripts' },
|
||||||
|
{ from: './node_modules/qrious/dist/qrious.min.js', to: 'scripts' },
|
||||||
]),
|
]),
|
||||||
extractCss,
|
extractCss,
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
|
|
Loading…
Reference in New Issue