Skip to content

Commit

Permalink
WebauthN flow(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Oct 30, 2024
1 parent 6361ffe commit a0c4eac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion vos/js/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const formTp = html`
<form>
<label>
<div class="label">${i18.user}</div>
<mx-id id="id" name="id" required></mx-id>
<mx-id id="id" name="username" required autocomplete="username webauthn"></mx-id>
</label>
<label>
<div class="label">${i18.pwd}</div>
Expand Down
30 changes: 15 additions & 15 deletions vos/js/vos-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Shell } from './sh.js'
// const tagFn = fn => (strings, ...parts) => fn(parts.reduce((tpl, value, i) => `${tpl}${strings[i]}${value}`, '').concat(strings[parts.length]))
// const html = tagFn(s => new DOMParser().parseFromString(`<template>${s}</template>`, 'text/html').querySelector('template'))
// const css = tagFn(s => new CSSStyleSheet().replace(s))
const SRC_URL = new URL(import.meta.url)
const SRC_URL = new URL(import.meta.url)
const PARAMS = SRC_URL.searchParams
const VOS_USER = 'vos-connect-user'

/*
* The Connect element includes everything you need to interact with VOS
Expand All @@ -16,12 +17,10 @@ export class Connect extends MxConnect {

sh = new Shell()

// constructor() {
// super()
// }

connectedCallback() {
super.connectedCallback()
let user = localStorage.getItem(VOS_USER)
if (user) console.log(user)
if (!this.deviceId) this.dataset.deviceId = randString(8)
}

Expand All @@ -33,23 +32,14 @@ export class Connect extends MxConnect {
}

async connect(user) {
if (!(window.PublicKeyCredential &&
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
PublicKeyCredential.isConditionalMediationAvailable)) {
await Promise.all([
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(),
PublicKeyCredential.isConditionalMediationAvailable(),
]).then(results => results.every(r => r === true))
}
await this.sh.connect(user)
}

get deviceId() { return this.dataset.deviceId }

}
if (PARAMS.get('def') != 'no') customElements.define(Connect.tag, Connect)

async function createAuthCredential(mxid, challenge) {
async function createCredential(mxid, challenge) {
await navigator.credentials.create({
publicKey: {
challenge: [],
Expand All @@ -76,6 +66,16 @@ async function createAuthCredential(mxid, challenge) {
})
}

async function getCredential(challenge) {
await navigator.credentials.get({
mediation: 'conditional',
publicKey: {
challenge,
rpId: SRC_URL.host,
}
})
}

function randString(length) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
return Array.from(
Expand Down

0 comments on commit a0c4eac

Please sign in to comment.