Skip to content

Commit

Permalink
Updated the non wokring demo.yubico.com example (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
virot authored Jan 21, 2025
1 parent e1ff3cf commit 79b5a3d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Docs/Examples/Enroll YubiKey FIDO2 against demo.yubico.com.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
## UNDER CONSTRUCTION ##
# Lets start by creating the information prior to creation.
# UNDER CONSTRUCTION #

### Lets start by creating the information prior to creation.
```pwsh
$username = "powershellYK$($(new-guid).tostring().Replace('-',''))"
$password = (get-date -Format 'yyyy-MM-dd')
$site = "demo.yubico.com"
```

# Now that we have a user and password, lets create the user in the Yubico playground
### Create the user in the Yubico playground
```pwsh
$createUser = @{
'displayName'='powershellYK Demo';
'namespace'='playground';
'username'=$username;
'password'=$password
} | ConvertTo-JSON

$userCreation = Invoke-RestMethod -Method Post -SessionVariable session -Uri "https://$site/api/v1/user" -Body $createUser -ContentType 'application/json'
```

#Lets begin registering the YubiKey
### Lets begin registering the YubiKey
```pwsh
$registerBeginBody = @{'authenticatorAttachment' = 'cross-platform'; 'residentKey' = $true} | ConvertTo-JSON
$registerBeginReturn = Invoke-RestMethod -Method Post -WebSession $session -Uri "https://$site/api/v1/user/$($userCreation.data.uuid)/webauthn/register-begin" -Body $registerBeginBody -ContentType 'application/json'
$userEntity = [Yubico.YubiKey.Fido2.UserEntity]::new([system.convert]::FromBase64String($registerBeginReturn.data.publicKey.user.id.'$base64'))
$userEntity.Name = $registerBeginReturn.data.publicKey.user.name
$userentity.DisplayName = $registerBeginReturn.data.publicKey.user.displayname


$out = New-YubiKeyFIDO2Credential -RelyingPartyID $registerBeginReturn.data.publicKey.rp.id -RelyingPartyName $registerBeginReturn.data.publicKey.rp.name -Discoverable $true -Challange $registerBeginReturn.data.publicKey.challenge.'$base64' -UserEntity $userEntity
```

# This Data is lost by the SDK so we need to build it backup. Wonder if this is where it breaks.
### Return the attestion data etc to the site
This Data is lost by the SDK so we need to build it backup. Wonder if this is where it breaks.
```pwsh
$a = [powershellYK.FIDO2.CredentialData]::new($out)
#[system.convert]::ToBase64String($a.w3cEncoded())

$clientDataJSON = @{
'type' = 'webauthn.create';
'challenge' = $registerBeginReturn.data.publicKey.challenge.'$base64' -replace '\+', '-' -replace '/', '_' -replace '=','';
Expand All @@ -45,3 +50,7 @@ $registerFinishBody = @{
}
} | ConvertTo-JSON -Compress
$registerFinishReturn = Invoke-RestMethod -Method Post -WebSession $session -Uri "https://$site/api/v1/user/$($userCreation.data.uuid)/webauthn/register-finish" -Body $registerFinishBody -ContentType 'application/json'
```

Here we should be done, but something is broken somewhere..

0 comments on commit 79b5a3d

Please sign in to comment.