authelia/web/src/services/SecurityKey.ts
Clement Michaud 9ae2096d2a Rewrite authelia frontend to improve user experience.
This refactoring simplify the code of the frontend and prepare the
portal for receiving a user settings page and an admin page.
2019-12-05 11:05:24 +01:00

31 lines
911 B
TypeScript

import { Post, PostWithOptionalResponse } from "./Client";
import { InitiateU2FSignInPath, CompleteU2FSignInPath } from "./Api";
import u2fApi from "u2f-api";
import { SignInResponse } from "./SignIn";
interface InitiateU2FSigninResponse {
appId: string,
challenge: string,
registeredKeys: {
appId: string,
keyHandle: string,
version: string,
}[]
}
export async function initiateU2FSignin() {
return Post<InitiateU2FSigninResponse>(InitiateU2FSignInPath);
}
interface CompleteU2FSigninBody {
signResponse: u2fApi.SignResponse;
targetURL?: string;
}
export function completeU2FSignin(signResponse: u2fApi.SignResponse, targetURL: string | undefined) {
const body: CompleteU2FSigninBody = { signResponse };
if (targetURL) {
body.targetURL = targetURL;
}
return PostWithOptionalResponse<SignInResponse>(CompleteU2FSignInPath, body);
}