Created
April 21, 2025 17:58
-
-
Save tonis2/8402c4ebb7f1411d2dfd63c2b4570581 to your computer and use it in GitHub Desktop.
Passkey actions on web, with dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:web/web.dart'; | |
register(String username, String email) async { | |
CredentialCreationOptions options = CredentialCreationOptions( | |
publicKey: PublicKeyCredentialCreationOptions( | |
rp: PublicKeyCredentialRpEntity(name: "test", id: "localhost"), | |
user: PublicKeyCredentialUserEntity( | |
displayName: username, | |
name: email, | |
id: Uint8List.fromList("test_id".codeUnits).toJS, | |
), | |
challenge: Uint8List(16).toJS, | |
authenticatorSelection: AuthenticatorSelectionCriteria(userVerification: "preferred"), | |
pubKeyCredParams: | |
[ | |
PublicKeyCredentialParameters(alg: -7, type: "public-key"), | |
PublicKeyCredentialParameters(alg: -8, type: "public-key"), | |
PublicKeyCredentialParameters(alg: -257, type: "public-key"), | |
].toJS, | |
// excludeCredentials: JSArray.from(PublicKeyCredentialDescriptor(type: "public-key", id: Uint8List(10).toJS)), | |
), | |
); | |
Credential? response = await window.navigator.credentials.create(options).toDart; | |
if (response != null) { | |
print(response.id); | |
print(response.type); | |
} | |
} | |
login() async { | |
CredentialRequestOptions options = CredentialRequestOptions( | |
publicKey: PublicKeyCredentialRequestOptions( | |
challenge: Uint8List(16).toJS, | |
rpId: "localhost", | |
timeout: 5000, | |
userVerification: "preferred", | |
allowCredentials: List<PublicKeyCredentialDescriptor>.from([]).toJS, | |
), | |
); | |
// PublicKeyCredentialDescriptor( | |
// id: Uint8List.fromList("EIMvQoA7UJJfBSISN295eQ".codeUnits).toJS, | |
// type: "public-key", | |
// transports: [""] | |
// ), | |
try { | |
Credential? response = await window.navigator.credentials.get(options).toDart; | |
if (response != null) { | |
print(response.id); | |
print(response.type); | |
} | |
} catch (err) { | |
print("failed geting auth"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment