mirror of https://github.com/Yubico/python-fido2
Fix outdated examples.
This commit is contained in:
parent
a046a5a9e8
commit
db24c8b6bf
|
@ -84,17 +84,18 @@ user = {"id": b"user_id", "name": "A. User"}
|
|||
# Prepare parameters for makeCredential
|
||||
create_options, state = server.register_begin(
|
||||
user,
|
||||
resident_key=True,
|
||||
resident_key_requirement="required",
|
||||
user_verification=uv,
|
||||
authenticator_attachment="cross-platform",
|
||||
)
|
||||
|
||||
# Add CredBlob extension, attach data
|
||||
blob = os.urandom(32) # 32 random bytes
|
||||
create_options["publicKey"].extensions = {"credBlob": blob}
|
||||
options = dict(create_options["publicKey"])
|
||||
options["extensions"] = {"credBlob": blob}
|
||||
|
||||
# Create a credential
|
||||
result = client.make_credential(create_options["publicKey"])
|
||||
result = client.make_credential(options)
|
||||
|
||||
# Complete registration
|
||||
auth_data = server.register_complete(
|
||||
|
@ -112,11 +113,12 @@ print("New credential created, with the CredBlob extension.")
|
|||
|
||||
# Prepare parameters for getAssertion
|
||||
request_options, state = server.authenticate_begin()
|
||||
request_options["publicKey"].extensions = {"getCredBlob": True}
|
||||
options = dict(request_options["publicKey"])
|
||||
options["extensions"] = {"getCredBlob": True}
|
||||
|
||||
# Authenticate the credential
|
||||
# Only one cred in allowCredentials, only one response.
|
||||
result = client.get_assertion(request_options["publicKey"]).get_response(0)
|
||||
result = client.get_assertion(options).get_response(0)
|
||||
|
||||
blob_res = result.authenticator_data.extensions.get("credBlob")
|
||||
|
||||
|
|
|
@ -101,8 +101,8 @@ create_options, state = server.register_begin(
|
|||
print("Creating a credential with LargeBlob support...")
|
||||
|
||||
# Enable largeBlob
|
||||
options = create_options["publicKey"]
|
||||
options.extensions = {"largeBlob": {"support": "required"}}
|
||||
options = dict(create_options["publicKey"])
|
||||
options["extensions"] = {"largeBlob": {"support": "required"}}
|
||||
|
||||
# Create a credential
|
||||
result = client.make_credential(options)
|
||||
|
@ -123,8 +123,8 @@ print("Credential created! Writing a blob...")
|
|||
request_options, state = server.authenticate_begin(user_verification=uv)
|
||||
|
||||
# Write a large blob
|
||||
options = request_options["publicKey"]
|
||||
options.extensions = {"largeBlob": {"write": b"Here is some data to store!"}}
|
||||
options = dict(request_options["publicKey"])
|
||||
options["extensions"] = {"largeBlob": {"write": b"Here is some data to store!"}}
|
||||
|
||||
# Authenticate the credential
|
||||
selection = client.get_assertion(options)
|
||||
|
@ -138,8 +138,8 @@ if not result.extension_results.get("written"):
|
|||
print("Blob written! Reading back the blob...")
|
||||
|
||||
# Read the blob
|
||||
options = request_options["publicKey"]
|
||||
options.extensions = {"largeBlob": {"read": True}}
|
||||
options = dict(request_options["publicKey"])
|
||||
options["extensions"] = {"largeBlob": {"read": True}}
|
||||
|
||||
# Authenticate the credential
|
||||
selection = client.get_assertion(options)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from fido2.pcsc import CtapPcscDevice
|
||||
from fido2.utils import sha256
|
||||
from fido2.ctap1 import CTAP1
|
||||
from fido2.ctap1 import Ctap1
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ if not dev:
|
|||
chal = sha256(b"AAA")
|
||||
appid = sha256(b"BBB")
|
||||
|
||||
ctap1 = CTAP1(dev)
|
||||
ctap1 = Ctap1(dev)
|
||||
|
||||
print("version:", ctap1.get_version())
|
||||
|
||||
|
|
Loading…
Reference in New Issue