2019-11-19 06:37:36 +07:00
|
|
|
import u2fApi from "u2f-api";
|
2021-01-02 17:58:24 +07:00
|
|
|
|
|
|
|
import { InitiateU2FSignInPath, CompleteU2FSignInPath } from "./Api";
|
|
|
|
import { Post, PostWithOptionalResponse } from "./Client";
|
2019-11-19 06:37:36 +07:00
|
|
|
import { SignInResponse } from "./SignIn";
|
|
|
|
|
|
|
|
interface InitiateU2FSigninResponse {
|
2021-01-02 17:58:24 +07:00
|
|
|
appId: string;
|
|
|
|
challenge: string;
|
2019-11-19 06:37:36 +07:00
|
|
|
registeredKeys: {
|
2021-01-02 17:58:24 +07:00
|
|
|
appId: string;
|
|
|
|
keyHandle: string;
|
|
|
|
version: string;
|
|
|
|
}[];
|
2019-11-19 06:37:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-01-02 17:58:24 +07:00
|
|
|
}
|