fix: Use `@simplewebauthn` for frontend logic
This simplifies the code a lot and fixes errors with the exisiting custom code, where slightly different base64 values were emitted which are not valid according to the standard. ref: https://github.com/web-auth/webauthn-framework/issues/510 Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>pull/44761/head
parent
e8452d9ef1
commit
3880e4c8d7
@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* @copyright 2020, Roeland Jago Douma <roeland@famdouma.nl>
|
|
||||||
*
|
|
||||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
||||||
*
|
|
||||||
* @license AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Axios from '@nextcloud/axios'
|
|
||||||
import { generateUrl } from '@nextcloud/router'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {any} loginName -
|
|
||||||
*/
|
|
||||||
export function startAuthentication(loginName) {
|
|
||||||
const url = generateUrl('/login/webauthn/start')
|
|
||||||
|
|
||||||
return Axios.post(url, { loginName })
|
|
||||||
.then(resp => resp.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {any} data -
|
|
||||||
*/
|
|
||||||
export function finishAuthentication(data) {
|
|
||||||
const url = generateUrl('/login/webauthn/finish')
|
|
||||||
|
|
||||||
return Axios.post(url, { data })
|
|
||||||
.then(resp => resp.data)
|
|
||||||
}
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* @copyright 2020, Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
|
*
|
||||||
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
|
*
|
||||||
|
* @license AGPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types'
|
||||||
|
|
||||||
|
import { startAuthentication as startWebauthnAuthentication } from '@simplewebauthn/browser'
|
||||||
|
import { generateUrl } from '@nextcloud/router'
|
||||||
|
|
||||||
|
import Axios from '@nextcloud/axios'
|
||||||
|
import logger from '../logger'
|
||||||
|
|
||||||
|
export class NoValidCredentials extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start webautn authentication
|
||||||
|
* This loads the challenge, connects to the authenticator and returns the repose that needs to be sent to the server.
|
||||||
|
*
|
||||||
|
* @param loginName Name to login
|
||||||
|
*/
|
||||||
|
export async function startAuthentication(loginName: string) {
|
||||||
|
const url = generateUrl('/login/webauthn/start')
|
||||||
|
|
||||||
|
const { data } = await Axios.post<PublicKeyCredentialRequestOptionsJSON>(url, { loginName })
|
||||||
|
if (!data.allowCredentials || data.allowCredentials.length === 0) {
|
||||||
|
logger.error('No valid credentials returned for webauthn')
|
||||||
|
throw new NoValidCredentials()
|
||||||
|
}
|
||||||
|
return await startWebauthnAuthentication(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify webauthn authentication
|
||||||
|
* @param authData The authentication data to sent to the server
|
||||||
|
*/
|
||||||
|
export async function finishAuthentication(authData: AuthenticationResponseJSON) {
|
||||||
|
const url = generateUrl('/login/webauthn/finish')
|
||||||
|
|
||||||
|
const { data } = await Axios.post(url, { data: JSON.stringify(authData) })
|
||||||
|
return data
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue