Skip to content

Commit

Permalink
feat: Enable webauthn plugin for security keys
Browse files Browse the repository at this point in the history
Change _urlsafe_b64recode to _unpadded_urlsafe_b64recode for clarity.
  • Loading branch information
cpisunyer committed Jun 5, 2024
1 parent ecc49de commit 8375dee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions google/oauth2/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ def _obtain_challenge_input_webauthn(self, metadata, webauthn_handler):

allow_credentials = []
for challenge in challenges:
key_handle = self._urlsafe_b64recode(challenge["keyHandle"])
kh = challenge.get("keyHandle")
if kh is None:
raise exceptions.InvalidValue("keyHandle is None")
key_handle = self._unpadded_urlsafe_b64recode(kh)
allow_credentials.append(PublicKeyCredentialDescriptor(id=key_handle))

extension = AuthenticationExtensionsClientInputs(appid=application_id)
Expand All @@ -219,7 +222,7 @@ def _obtain_challenge_input_webauthn(self, metadata, webauthn_handler):
get_request = GetRequest(
origin=REAUTH_ORIGIN,
rpid=relying_party_id,
challenge=self._urlsafe_b64recode(challenge),
challenge=self._unpadded_urlsafe_b64recode(challenge),
timeout_ms=WEBAUTHN_TIMEOUT_MS,
allow_credentials=allow_credentials,
user_verification="required",
Expand All @@ -242,7 +245,7 @@ def _obtain_challenge_input_webauthn(self, metadata, webauthn_handler):
}
return {"securityKey": response}

def _urlsafe_b64recode(self, s):
def _unpadded_urlsafe_b64recode(self, s):
"""Converts standard b64 encoded string to url safe b64 encoded string
with no padding."""
b = base64.urlsafe_b64decode(s)
Expand Down

0 comments on commit 8375dee

Please sign in to comment.