-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webauthn): make webauthn params configurable (#48) & add mfa routes
* feat(webauthn): make webauthn params configurable * add attachment, attestation preference and resident key requirement params to create and update tenant endpoints * add fallback values when params are not provided * add migrations for new fields in webauthn config in database * reflect changes in README.md and admin spec Closes: #45 * feat(webauthn): allow optional user_id for login/initialize * add login init dto with user_id as optional param * extend service to switch to BeginLogin /ValidateLogin when user_id was given * extend database to persist login state in sessiondata for login/finalize * extend openapi spec to reflect optional user_id parameter for login/initialize Closes: #33 * feat(mfa): add multi factor authentication endpoints * add config for mfa passkeys * add endpoints for mfa passkeys TODO: add docs Closes: #45 * feat(mfa): rework mfa persistence * mfa config has now its own database table * mfa config does not require RP config anymore * webauthn client for mfa uses rp from passkey config * update openapi specs to reflect changes Closes: #45 * fix(credentials): add is_mfa flag to discern creds * add is_mfa to DTO Closes: #45 * chore(webauthn): change attestation default mode * change attestation default mode from 'none' to 'direct' Closes: #45 * fix(webauthn): make mfa config optional * make MFA config optional for backwards compatibility * rename some variables for better clarity * add audit log types for MFA login for better distinction * add missing attachment option to mfa client * add api key vs tenant secrets check for mfa/non-discover login Closes: #45 * fix(openapi): make mfa config optional Closes: #45 * fix(dto): use mfa defaults instead of passkey options use mfa default params instead of passkey dto ones when creating a mfa default config on admin operations `create tenant` or `update config` * fix(dto): add missing commas ... * fix(login): use sessiondata userID as userHandle for login Use sessionData userId as userhandle when login is MFA or non-discoverable. Also check if credential is in allowed list Closes: #45 * fix(login): remove cred check credential check will be done by go-webauthn lib Closes: #45 * fix(mfa): filter credentials on non mfa methods * remove mfa credentials from allowedCredentials when using non mfa routes * for good measure also remove mfa credentials from FindCredentialById when used on Non-MFA routes * rename CreateApiKeyError to CheckApiKey * increase versions of openapi spec * change defaults for mfa config object in admin spec * cleanup: remove unused methods from handler/webauthn.go Closes: #45 --------- Co-authored-by: Stefan Jacobi <[email protected]>
- Loading branch information
1 parent
aab9319
commit 442450c
Showing
49 changed files
with
1,115 additions
and
260 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/go-webauthn/webauthn/protocol" | ||
"github.com/gofrs/uuid" | ||
"github.com/teamhanko/passkey-server/persistence/models" | ||
"time" | ||
) | ||
|
||
type CreateMFAConfigDto struct { | ||
Timeout int `json:"timeout" validate:"required,number"` | ||
UserVerification *protocol.UserVerificationRequirement `json:"user_verification" validate:"omitempty,oneof=required preferred discouraged"` | ||
Attachment *protocol.AuthenticatorAttachment `json:"attachment" validate:"omitempty,oneof=platform cross-platform"` | ||
AttestationPreference *protocol.ConveyancePreference `json:"attestation_preference" validate:"omitempty,oneof=none indirect direct enterprise"` | ||
ResidentKeyRequirement *protocol.ResidentKeyRequirement `json:"resident_key_requirement" validate:"omitempty,oneof=discouraged preferred required"` | ||
} | ||
|
||
func (dto *CreateMFAConfigDto) ToModel(configModel models.Config) models.MfaConfig { | ||
mfaConfigId, _ := uuid.NewV4() | ||
now := time.Now() | ||
|
||
mfaConfig := models.MfaConfig{ | ||
ID: mfaConfigId, | ||
ConfigID: configModel.ID, | ||
Timeout: dto.Timeout, | ||
CreatedAt: now, | ||
UpdatedAt: now, | ||
} | ||
|
||
if dto.AttestationPreference == nil { | ||
mfaConfig.AttestationPreference = protocol.PreferDirectAttestation | ||
} else { | ||
mfaConfig.AttestationPreference = *dto.AttestationPreference | ||
} | ||
|
||
if dto.ResidentKeyRequirement == nil { | ||
mfaConfig.ResidentKeyRequirement = protocol.ResidentKeyRequirementDiscouraged | ||
} else { | ||
mfaConfig.ResidentKeyRequirement = *dto.ResidentKeyRequirement | ||
} | ||
|
||
if dto.UserVerification == nil { | ||
mfaConfig.UserVerification = protocol.VerificationPreferred | ||
} else { | ||
mfaConfig.UserVerification = *dto.UserVerification | ||
} | ||
|
||
if dto.Attachment == nil { | ||
mfaConfig.Attachment = protocol.CrossPlatform | ||
} else { | ||
mfaConfig.Attachment = *dto.Attachment | ||
} | ||
|
||
return mfaConfig | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package response | ||
|
||
import ( | ||
"github.com/go-webauthn/webauthn/protocol" | ||
"github.com/teamhanko/passkey-server/persistence/models" | ||
) | ||
|
||
type GetMFAResponse struct { | ||
Timeout int `json:"timeout"` | ||
UserVerification protocol.UserVerificationRequirement `json:"user_verification"` | ||
Attachment protocol.AuthenticatorAttachment `json:"attachment"` | ||
AttestationPreference protocol.ConveyancePreference `json:"attestation_preference"` | ||
ResidentKeyRequirement protocol.ResidentKeyRequirement `json:"resident_key_requirement"` | ||
} | ||
|
||
func ToGetMFAResponse(webauthn *models.MfaConfig) GetMFAResponse { | ||
return GetMFAResponse{ | ||
Timeout: webauthn.Timeout, | ||
UserVerification: webauthn.UserVerification, | ||
Attachment: webauthn.Attachment, | ||
AttestationPreference: webauthn.AttestationPreference, | ||
ResidentKeyRequirement: webauthn.ResidentKeyRequirement, | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.