face id/touch id supports ios safari

This commit is contained in:
MaysWind
2020-11-22 23:53:52 +08:00
parent ae5af160c9
commit dc78f5fa7e
4 changed files with 43 additions and 23 deletions
+8 -6
View File
@@ -7,26 +7,28 @@ const publicKeyCredentialCreationOptionsBaseTemplate = {
authenticatorSelection: {
authenticatorAttachment: 'platform',
requireResidentKey: false,
userVerification: "required"
userVerification: "discouraged"
},
pubKeyCredParams: [
// https://www.iana.org/assignments/cose/cose.xhtml#algorithms
{type: "public-key", alg: -7}, // ECDSA w/ SHA-256
{type: "public-key", alg: -257}, // RSASSA-PKCS1-v1_5 using SHA-256
],
timeout: 1800000
timeout: 120000
};
const publicKeyCredentialRequestOptionsBaseTemplate = {
allowCredentials: [{
type: 'public-key'
}],
userVerification: "required",
timeout: 1800000
}
userVerification: "discouraged",
timeout: 120000
};
function isSupported() {
return !!window.PublicKeyCredential && !!navigator.credentials;
return !!window.PublicKeyCredential
&& !!navigator.credentials
&& utils.isFunction(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable);
}
function isCompletelySupported() {
+3 -1
View File
@@ -278,7 +278,8 @@ export default {
'Statistics': 'Statistics',
'Settings': 'Settings',
'Back': 'Back',
'Unlock': 'Unlock',
'Unlock By PIN Code': 'Unlock By PIN Code',
'Unlock By Face ID/Touch ID': 'Unlock By Face ID/Touch ID',
'Re-login': 'Re-login',
'Username': 'Username',
'Your username': 'Your username',
@@ -426,6 +427,7 @@ export default {
'User has canceled authentication': 'User has canceled authentication',
'User has canceled or this device does not support Face ID/Touch ID': 'User has canceled or this device does not support Face ID/Touch ID',
'Failed to authenticate by Face ID/Touch ID': 'Failed to authenticate by Face ID/Touch ID',
'Face ID/Touch ID authentication is not enabled': 'Face ID/Touch ID authentication is not enabled',
'Exchange Rates Data': 'Exchange Rates Data',
'Base Currency': 'Base Currency',
'Last Updated': 'Last Updated',
+7 -5
View File
@@ -278,7 +278,8 @@ export default {
'Statistics': '统计',
'Settings': '设置',
'Back': '返回',
'Unlock': '解锁',
'Unlock By PIN Code': '使用PIN码解锁',
'Unlock By Face ID/Touch ID': '使用面容ID/指纹ID解锁',
'Re-login': '重新登陆',
'Username': '用户名',
'Your username': '你的用户名',
@@ -421,11 +422,12 @@ export default {
'Please enter your current PIN code when disable application lock': '禁用应用锁时需要输入当前的PIN码',
'Face ID / Touch ID': '面容ID / 指纹ID',
'You have enabled Face ID/Touch ID successfully': '您已经成功开启面容ID/指纹ID',
'This device does not support Face ID/Touch ID': '当前设备不支持 Face ID 或 Touch ID',
'Failed to enable Face ID/Touch ID': '启用 Face ID 或 Touch ID 失败',
'This device does not support Face ID/Touch ID': '当前设备不支持面容ID或指纹ID',
'Failed to enable Face ID/Touch ID': '启用面容ID或指纹ID失败',
'User has canceled authentication': '用户已经取消认证',
'User has canceled or this device does not support Face ID/Touch ID': '用户已取消或当前设备不支持 Face ID 或 Touch ID',
'Failed to authenticate by Face ID/Touch ID': '使用 Face ID / Touch ID 认证失败',
'User has canceled or this device does not support Face ID/Touch ID': '用户已取消或当前设备不支持面容ID/指纹ID',
'Failed to authenticate by Face ID/Touch ID': '使用面容ID或指纹ID认证失败',
'Face ID/Touch ID authentication is not enabled': '面容ID或指纹ID认证没有启用',
'Exchange Rates Data': '汇率数据',
'Base Currency': '基准货币',
'Last Updated': '最后更新',
+21 -7
View File
@@ -3,11 +3,12 @@
<f7-login-screen-title>{{ $t('PIN Code') }}</f7-login-screen-title>
<f7-list form>
<f7-list-item class="list-item-pincode-input">
<PincodeInput secure :length="6" v-model="pinCode" @keyup.native="unlock" />
<PincodeInput secure :length="6" v-model="pinCode" @keyup.native="unlockByPin" />
</f7-list-item>
</f7-list>
<f7-list>
<f7-list-button :class="{ 'disabled': !pinCodeValid }" :text="$t('Unlock')" @click="unlock"></f7-list-button>
<f7-list-button :class="{ 'disabled': !pinCodeValid }" :text="$t('Unlock By PIN Code')" @click="unlockByPin"></f7-list-button>
<f7-list-button v-if="isWebAuthnAvailable" :text="$t('Unlock By Face ID/Touch ID')" @click="unlockByWebAuthn"></f7-list-button>
<f7-block-footer>
<f7-link :text="$t('Re-login')" @click="relogin"></f7-link>
</f7-block-footer>
@@ -23,15 +24,30 @@ export default {
}
},
computed: {
isWebAuthnAvailable() {
return this.$settings.isEnableApplicationLockWebAuthn()
&& this.$user.getWebAuthnCredentialId()
&& this.$webauthn.isSupported();
},
pinCodeValid() {
return this.pinCode && this.pinCode.length === 6;
}
},
created() {
methods: {
unlockByWebAuthn() {
const self = this;
const router = self.$f7router;
if (self.$settings.isEnableApplicationLockWebAuthn() && self.$user.getWebAuthnCredentialId()) {
if (!self.$settings.isEnableApplicationLockWebAuthn() || !self.$user.getWebAuthnCredentialId()) {
self.$toast('Face ID/Touch ID authentication is not enabled');
return;
}
if (!self.$webauthn.isSupported()) {
self.$toast('This device does not support Face ID/Touch ID');
return;
}
self.$showLoading();
self.$webauthn.verifyCredential(
@@ -62,10 +78,8 @@ export default {
self.$toast('User has canceled or this device does not support Face ID/Touch ID');
}
});
}
},
methods: {
unlock() {
unlockByPin() {
const app = this.$f7;
const $$ = app.$;