getCredential method

  1. @override
Future<AuthenticationPublicKeyCredential> getCredential(
  1. AuthenticateInitResponse authenticateData
)
override

Implementation

@override
Future<AuthenticationPublicKeyCredential> getCredential(AuthenticateInitResponse authenticateData) async {

  var options = web.PublicKeyCredentialRequestOptions(
    challenge: Uint8List.fromList(authenticateData.authenticationData.challenge).toJS,
    rpId: authenticateData.domain,
    userVerification: authenticateData.authenticationData.userVerification.name.toLowerCase()
  );
  if (authenticateData.authenticationData.allowedCredentials != null) {
    options.allowCredentials = (authenticateData.authenticationData.allowedCredentials!.map((element) => web.PublicKeyCredentialDescriptor(type: element.type, id: element.id.toJS, transports: element.transports.map((s) => s.toJS).toList().toJS)).toList()).toJS;
  }

  final publicKeyCredential = await (web.window.navigator.credentials.get(web.CredentialRequestOptions(publicKey: options))).toDart as web.PublicKeyCredential;
  final authenticatorResponse = publicKeyCredential.response as web.AuthenticatorAssertionResponse;

  return AuthenticationPublicKeyCredential(
    publicKeyCredential.id,
    publicKeyCredential.rawId.toDart.asUint8List(),
    publicKeyCredential.type,
    AuthenticatorAssertionResponse(
      authenticatorResponse.authenticatorData.toDart.asUint8List(),
      authenticatorResponse.clientDataJSON.toDart.asUint8List(),
      authenticatorResponse.signature.toDart.asUint8List(),
      authenticatorResponse.userHandle?.toDart.asUint8List(),
    )
  );
}