...
To register a FIDO2 key for a user, we call 2 DualShield APIs
| Expand |
|---|
|
| Include Page |
|---|
| token/preRegister |
|---|
| token/preRegister |
|---|
|
|
| Expand |
|---|
|
| Include Page |
|---|
| token/register |
|---|
| token/register |
|---|
|
|
...
Pre-Reigster FIDO2 Token
First, we can the DualShield API token/preRegister to pre-register a FIDO2 token
| Code Block |
|---|
|
let json = {
product: this.fidoObj,
user: { loginName: this.loginName}, \\ Pass the user name for which the Fido2 key needs to be registered
}; |
The response from the preRegister API call is then passed to the CredentialCreationOptionsJSON object
| Code Block |
|---|
|
\\ response is stored in data
this.registerRequestId = data.result.registerRequestId;
let registerObj = JSON.parse(data.result.registerRequestData);
if(registerObj){
this.credentialCreateOptions.publicKey.rp.id = registerObj.rp.id;
this.credentialCreateOptions.publicKey.rp.name = registerObj.rp.name;
this.credentialCreateOptions.publicKey.user.displayName = registerObj.user.displayName;
this.credentialCreateOptions.publicKey.user.id = registerObj.user.id;
this.credentialCreateOptions.publicKey.user.name = registerObj.user.name;
this.credentialCreateOptions.publicKey.timeout = 180000; //Set to 3 minutes
this.credentialCreateOptions.publicKey.challenge = registerObj.challenge;
this.credentialCreateOptions.publicKey.pubKeyCredParams = registerObj.pubKeyCredParams;
this.credentialCreateOptions.publicKey.attestation = registerObj.attestation;
this.credentialCreateOptions.publicKey.excludeCredentials = registerObj.excludeCredentials;
this.credentialCreateOptions.publicKey.authenticatorSelection.userVerification= registerObj.authenticatorSelection.userVerification;
} |
Now, pass the CredentialCreationOptionsJSON object to the create API in the WebAuthn-Jason library
| Code Block |
|---|
|
create(this.credentialCreateOptions).then((response: any) => {
let token: {publicKeyCredentialJson: string, pin?: string, registerRequestId: string} = {
publicKeyCredentialJson: JSON.stringify(response),
registerRequestId: this.registerRequestId,
}; |
Reigster FIDO2 Token to a user
Finally, we call the DualShield API token/register to register the FIDO2 token
| Code Block |
|---|
|
let json = {
product:{productCode: this.fidoObj.productCode},
application: {name: ""},
user: { loginName: this.loginName },
token: token
}; |