From 853ce063bda3eb68080d547ee212a14f092db27c Mon Sep 17 00:00:00 2001 From: Tyler Noblett Date: Wed, 10 May 2023 15:56:02 -0400 Subject: [PATCH 1/2] change key name to credential name --- backend/authschemes/webauthn/dtos.go | 4 +-- backend/authschemes/webauthn/types.go | 4 +-- backend/authschemes/webauthn/webauthn.go | 30 +++++++++---------- backend/authschemes/webauthn/webauthnuser.go | 14 ++++----- .../src/authschemes/webauthn/linker/index.tsx | 12 ++++---- .../src/authschemes/webauthn/login/index.tsx | 4 +-- frontend/src/authschemes/webauthn/services.ts | 10 +++---- .../authschemes/webauthn/settings/index.tsx | 30 +++++++++---------- frontend/src/authschemes/webauthn/types.ts | 2 +- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/backend/authschemes/webauthn/dtos.go b/backend/authschemes/webauthn/dtos.go index 3e6aebfc4..9d21e113e 100644 --- a/backend/authschemes/webauthn/dtos.go +++ b/backend/authschemes/webauthn/dtos.go @@ -10,6 +10,6 @@ type ListKeysOutput struct { } type KeyEntry struct { - KeyName string `json:"keyName"` - DateCreated time.Time `json:"dateCreated"` + CredentialName string `json:"credentialName"` + DateCreated time.Time `json:"dateCreated"` } diff --git a/backend/authschemes/webauthn/types.go b/backend/authschemes/webauthn/types.go index 27f8b4d1e..d1e2e8f2b 100644 --- a/backend/authschemes/webauthn/types.go +++ b/backend/authschemes/webauthn/types.go @@ -20,7 +20,7 @@ type WebAuthnRegistrationInfo struct { Username string FirstName string LastName string - KeyName string + CredentialName string UserID int64 RegistrationType RegistrationType ExistingCredentials []AShirtWebauthnCredential @@ -28,7 +28,7 @@ type WebAuthnRegistrationInfo struct { } type AShirtWebauthnExtension struct { - KeyName string `json:"keyName"` + CredentialName string `json:"credentialName"` KeyCreatedDate time.Time `json:"keyCreatedDate"` } diff --git a/backend/authschemes/webauthn/webauthn.go b/backend/authschemes/webauthn/webauthn.go index 8fd14bceb..25f79c177 100644 --- a/backend/authschemes/webauthn/webauthn.go +++ b/backend/authschemes/webauthn/webauthn.go @@ -107,7 +107,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) Username: dr.FromBody("username").Required().AsString(), FirstName: dr.FromBody("firstName").Required().AsString(), LastName: dr.FromBody("lastName").Required().AsString(), - KeyName: dr.FromBody("keyName").Required().AsString(), + CredentialName: dr.FromBody("credentialName").Required().AsString(), RegistrationType: CreateKey, } if dr.Error != nil { @@ -194,7 +194,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) dr := remux.DissectJSONRequest(r) info := WebAuthnRegistrationInfo{ Username: dr.FromBody("username").Required().AsString(), - KeyName: dr.FromBody("keyName").Required().AsString(), + CredentialName: dr.FromBody("credentialName").Required().AsString(), UserID: callingUserId, RegistrationType: LinkKey, } @@ -227,14 +227,14 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) return a.getKeys(callingUserID, bridge) })) - remux.Route(r, "DELETE", "/key/{keyName}", remux.JSONHandler(func(r *http.Request) (interface{}, error) { + remux.Route(r, "DELETE", "/key/{credentialName}", remux.JSONHandler(func(r *http.Request) (interface{}, error) { callingUserID := middleware.UserID(r.Context()) dr := remux.DissectJSONRequest(r) - keyName := dr.FromURL("keyName").Required().AsString() + credentialName := dr.FromURL("credentialName").Required().AsString() if dr.Error != nil { return nil, dr.Error } - return nil, a.deleteKey(callingUserID, keyName, bridge) + return nil, a.deleteKey(callingUserID, credentialName, bridge) })) remux.Route(r, "POST", "/key/add/begin", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -245,14 +245,14 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) } dr := remux.DissectJSONRequest(r) - keyName := dr.FromBody("keyName").Required().AsString() + credentialName := dr.FromBody("credentialName").Required().AsString() if dr.Error != nil { return nil, dr.Error } info := WebAuthnRegistrationInfo{ Username: auth.Username, - KeyName: keyName, + CredentialName: credentialName, UserID: auth.UserID, RegistrationType: AddKey, } @@ -302,15 +302,15 @@ func (a WebAuthn) getKeys(userID int64, bridge authschemes.AShirtAuthBridge) (*L results := helpers.Map(creds, func(cred AShirtWebauthnCredential) KeyEntry { return KeyEntry{ - KeyName: cred.KeyName, - DateCreated: cred.KeyCreatedDate, + CredentialName: cred.CredentialName, + DateCreated: cred.KeyCreatedDate, } }) output := ListKeysOutput{results} return &output, nil } -func (a WebAuthn) deleteKey(userID int64, keyName string, bridge authschemes.AShirtAuthBridge) error { +func (a WebAuthn) deleteKey(userID int64, credentialName string, bridge authschemes.AShirtAuthBridge) error { auth, err := bridge.FindUserAuthByUserID(userID) if err != nil { return backend.WrapError("Unable to find user", err) @@ -323,7 +323,7 @@ func (a WebAuthn) deleteKey(userID int64, keyName string, bridge authschemes.ASh } results := helpers.Filter(creds, func(cred AShirtWebauthnCredential) bool { - return cred.KeyName != keyName + return cred.CredentialName != credentialName }) encodedCreds, err := json.Marshal(results) if err != nil { @@ -339,11 +339,11 @@ func (a WebAuthn) deleteKey(userID int64, keyName string, bridge authschemes.ASh func (a WebAuthn) beginRegistration(w http.ResponseWriter, r *http.Request, bridge authschemes.AShirtAuthBridge, info WebAuthnRegistrationInfo) (*protocol.CredentialCreation, error) { var user webauthnUser if info.RegistrationType == CreateKey { - user = makeNewWebAuthnUser(info.FirstName, info.LastName, info.Email, info.Username, info.KeyName) + user = makeNewWebAuthnUser(info.FirstName, info.LastName, info.Email, info.Username, info.CredentialName) } else if info.RegistrationType == LinkKey { - user = makeLinkingWebAuthnUser(info.UserID, info.Username, info.KeyName) + user = makeLinkingWebAuthnUser(info.UserID, info.Username, info.CredentialName) } else { // Add Key - user = makeAddKeyWebAuthnUser(info.UserID, info.KeyName, info.Username, info.ExistingCredentials) + user = makeAddKeyWebAuthnUser(info.UserID, info.CredentialName, info.Username, info.ExistingCredentials) } credExcludeList := make([]protocol.CredentialDescriptor, len(user.Credentials)) @@ -422,7 +422,7 @@ func (a WebAuthn) validateRegistrationComplete(r *http.Request, bridge authschem } data.UserData.Credentials = append(data.UserData.Credentials, wrapCredential(*cred, AShirtWebauthnExtension{ - KeyName: data.UserData.KeyName, + CredentialName: data.UserData.CredentialName, KeyCreatedDate: data.UserData.KeyCreatedDate, })) diff --git a/backend/authschemes/webauthn/webauthnuser.go b/backend/authschemes/webauthn/webauthnuser.go index 925ba7268..4cdae59d0 100644 --- a/backend/authschemes/webauthn/webauthnuser.go +++ b/backend/authschemes/webauthn/webauthnuser.go @@ -19,34 +19,34 @@ type webauthnUser struct { FirstName string LastName string Email string - KeyName string + CredentialName string KeyCreatedDate time.Time } -func makeNewWebAuthnUser(firstName, lastName, email, username, keyName string) webauthnUser { +func makeNewWebAuthnUser(firstName, lastName, email, username, credentialName string) webauthnUser { return webauthnUser{ AuthnID: []byte(uuid.New().String()), UserName: username, FirstName: firstName, LastName: lastName, Email: email, - KeyName: keyName, + CredentialName: credentialName, KeyCreatedDate: time.Now(), } } -func makeLinkingWebAuthnUser(userID int64, username, keyName string) webauthnUser { +func makeLinkingWebAuthnUser(userID int64, username, credentialName string) webauthnUser { return webauthnUser{ UserID: i64ToByteSlice(userID), AuthnID: []byte(uuid.New().String()), UserName: username, - KeyName: keyName, + CredentialName: credentialName, KeyCreatedDate: time.Now(), } } -func makeAddKeyWebAuthnUser(userID int64, username, keyName string, creds []AShirtWebauthnCredential) webauthnUser { - user := makeLinkingWebAuthnUser(userID, username, keyName) +func makeAddKeyWebAuthnUser(userID int64, username, credentialName string, creds []AShirtWebauthnCredential) webauthnUser { + user := makeLinkingWebAuthnUser(userID, username, credentialName) user.Credentials = creds return user } diff --git a/frontend/src/authschemes/webauthn/linker/index.tsx b/frontend/src/authschemes/webauthn/linker/index.tsx index 560ddf409..337cfa8e4 100644 --- a/frontend/src/authschemes/webauthn/linker/index.tsx +++ b/frontend/src/authschemes/webauthn/linker/index.tsx @@ -19,25 +19,25 @@ export default (props: { }) => { const initialUsername = props.userData.authSchemes.find(s => s.schemeType == 'local')?.username const username = useFormField(initialUsername ?? "") - const keyName = useFormField('') + const credentialName = useFormField('') const [allowUsernameOverride, setOverride] = React.useState(false) const formComponentProps = useForm({ - fields: [username, keyName], + fields: [username, credentialName], onSuccess: () => props.onSuccess(), handleSubmit: async () => { if (username.value === '') { return Promise.reject(new Error("Username must be populated")) } - if (keyName.value === '') { - return Promise.reject(new Error("Key name must be populated")) + if (credentialName.value === '') { + return Promise.reject(new Error("Credential name must be populated")) } let reg = null try { reg = await beginLink({ username: username.value, - keyName: keyName.value, + credentialName: credentialName.value, }) } catch (err) { @@ -79,7 +79,7 @@ export default (props: { return (
- +
) } diff --git a/frontend/src/authschemes/webauthn/login/index.tsx b/frontend/src/authschemes/webauthn/login/index.tsx index c26be5db7..a053998c4 100644 --- a/frontend/src/authschemes/webauthn/login/index.tsx +++ b/frontend/src/authschemes/webauthn/login/index.tsx @@ -106,7 +106,7 @@ const RegisterModal = (props: { lastName: lastNameField.value, email: emailField.value, username: usernameField.value, - keyName: keyNameField.value, + credentialName: keyNameField.value, }) const credOptions = convertToCredentialCreationOptions(reg) @@ -140,7 +140,7 @@ const RegisterModal = (props: { - + ) diff --git a/frontend/src/authschemes/webauthn/services.ts b/frontend/src/authschemes/webauthn/services.ts index e7f3e2523..c50b7cea9 100644 --- a/frontend/src/authschemes/webauthn/services.ts +++ b/frontend/src/authschemes/webauthn/services.ts @@ -17,7 +17,7 @@ export async function beginRegistration(i: { username: string, firstName: string, lastName: string - keyName: string + credentialName: string }): Promise { return await req('POST', '/auth/webauthn/register/begin', i) } @@ -38,7 +38,7 @@ export async function finishLogin(i: CompletedLoginChallenge): Promise { export async function beginLink(i: { username: string, - keyName: string + credentialName: string }): Promise { return await req('POST', '/auth/webauthn/link/begin', i) } @@ -48,7 +48,7 @@ export async function finishLinking(i: WebAuthNRegisterConfirmation) { } export async function beginAddKey(i: { - keyName: string + credentialName: string }): Promise { return await req('POST', '/auth/webauthn/key/add/begin', i) } @@ -69,6 +69,6 @@ export async function listWebauthnKeys(): Promise { } -export async function deleteWebauthnKey(i: { keyName: string }): Promise { - return await req('DELETE', `/auth/webauthn/key/${i.keyName}`) +export async function deleteWebauthnKey(i: { credentialName: string }): Promise { + return await req('DELETE', `/auth/webauthn/key/${i.credentialName}`) } diff --git a/frontend/src/authschemes/webauthn/settings/index.tsx b/frontend/src/authschemes/webauthn/settings/index.tsx index e1e8464da..1dd9a1dbc 100644 --- a/frontend/src/authschemes/webauthn/settings/index.tsx +++ b/frontend/src/authschemes/webauthn/settings/index.tsx @@ -44,22 +44,22 @@ const KeyList = (props: { return () => { props.offReload(wiredKeys.reload) } }) - const deleteModal = useModal<{ keyName: string }>(mProps => , wiredKeys.reload) + const deleteModal = useModal<{ credentialName: string }>(mProps => , wiredKeys.reload) return (<> {wiredKeys.render(data => { return (
- +
{data.keys.map(keyEntry => { - const { keyName, dateCreated } = keyEntry + const { credentialName, dateCreated } = keyEntry return ( - - + +
{keyName}
{credentialName} {toEnUSDate(dateCreated)} @@ -93,16 +93,16 @@ const AddKeyButton = (props: { const AddKeyModal = (props: { onRequestClose: () => void, }) => { - const keyName = useFormField("") + const credentialName = useFormField("") const formComponentProps = useForm({ - fields: [keyName], + fields: [credentialName], handleSubmit: async () => { - if (keyName.value === '') { - return Promise.reject(new Error("Key name must be populated")) + if (credentialName.value === '') { + return Promise.reject(new Error("Credential name must be populated")) } const reg = await beginAddKey({ - keyName: keyName.value, + credentialName: credentialName.value, }) const credOptions = convertToCredentialCreationOptions(reg) @@ -135,21 +135,21 @@ const AddKeyModal = (props: { onRequestClose={props.onRequestClose} {...formComponentProps} > - + ) } const DeleteKeyModal = (props: { - keyName: string, + credentialName: string, onRequestClose: () => void, }) => ( deleteWebauthnKey({ keyName: props.keyName })} + challengeText={props.credentialName} + handleSubmit={() => deleteWebauthnKey({ credentialName: props.credentialName })} onRequestClose={props.onRequestClose} /> ) diff --git a/frontend/src/authschemes/webauthn/types.ts b/frontend/src/authschemes/webauthn/types.ts index 95d80e4a1..b93e89e0d 100644 --- a/frontend/src/authschemes/webauthn/types.ts +++ b/frontend/src/authschemes/webauthn/types.ts @@ -61,6 +61,6 @@ export type KeyList = { } export type KeyEntry = { - keyName: string + credentialName: string dateCreated: Date } From 7b16b9d5e4c22609195caffe132ee9162390e8b3 Mon Sep 17 00:00:00 2001 From: Tyler Noblett Date: Thu, 11 May 2023 12:45:25 -0400 Subject: [PATCH 2/2] change other instances of key to credential --- backend/authschemes/webauthn/dtos.go | 6 +- backend/authschemes/webauthn/types.go | 30 +++++----- backend/authschemes/webauthn/webauthn.go | 50 ++++++++-------- backend/authschemes/webauthn/webauthnuser.go | 46 +++++++-------- frontend/src/authschemes/webauthn/services.ts | 26 ++++----- .../authschemes/webauthn/settings/index.tsx | 58 +++++++++---------- .../webauthn/settings/stylesheet.styl | 4 +- frontend/src/authschemes/webauthn/types.ts | 6 +- 8 files changed, 113 insertions(+), 113 deletions(-) diff --git a/backend/authschemes/webauthn/dtos.go b/backend/authschemes/webauthn/dtos.go index 9d21e113e..352901a6e 100644 --- a/backend/authschemes/webauthn/dtos.go +++ b/backend/authschemes/webauthn/dtos.go @@ -5,11 +5,11 @@ package webauthn import "time" -type ListKeysOutput struct { - Keys []KeyEntry `json:"keys"` +type ListCredentialsOutput struct { + Credentials []CredentialEntry `json:"credentials"` } -type KeyEntry struct { +type CredentialEntry struct { CredentialName string `json:"credentialName"` DateCreated time.Time `json:"dateCreated"` } diff --git a/backend/authschemes/webauthn/types.go b/backend/authschemes/webauthn/types.go index d1e2e8f2b..ad2ed34a4 100644 --- a/backend/authschemes/webauthn/types.go +++ b/backend/authschemes/webauthn/types.go @@ -9,27 +9,27 @@ import ( type RegistrationType int const ( - // CreateOrLinkKey reflects the usecase where - CreateKey RegistrationType = iota - LinkKey - AddKey + // CreateOrLinkCredential reflects the usecase where + CreateCredential RegistrationType = iota + LinkCredential + AddCredential ) type WebAuthnRegistrationInfo struct { - Email string - Username string - FirstName string - LastName string - CredentialName string - UserID int64 - RegistrationType RegistrationType - ExistingCredentials []AShirtWebauthnCredential - KeyCreatedDate time.Time + Email string + Username string + FirstName string + LastName string + CredentialName string + UserID int64 + RegistrationType RegistrationType + ExistingCredentials []AShirtWebauthnCredential + CredentialCreatedDate time.Time } type AShirtWebauthnExtension struct { - CredentialName string `json:"credentialName"` - KeyCreatedDate time.Time `json:"keyCreatedDate"` + CredentialName string `json:"credentialName"` + CredentialCreatedDate time.Time `json:"credentialCreatedDate"` } type AShirtWebauthnCredential struct { diff --git a/backend/authschemes/webauthn/webauthn.go b/backend/authschemes/webauthn/webauthn.go index 25f79c177..85c9a5d11 100644 --- a/backend/authschemes/webauthn/webauthn.go +++ b/backend/authschemes/webauthn/webauthn.go @@ -108,7 +108,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) FirstName: dr.FromBody("firstName").Required().AsString(), LastName: dr.FromBody("lastName").Required().AsString(), CredentialName: dr.FromBody("credentialName").Required().AsString(), - RegistrationType: CreateKey, + RegistrationType: CreateCredential, } if dr.Error != nil { return nil, dr.Error @@ -196,7 +196,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) Username: dr.FromBody("username").Required().AsString(), CredentialName: dr.FromBody("credentialName").Required().AsString(), UserID: callingUserId, - RegistrationType: LinkKey, + RegistrationType: LinkCredential, } if dr.Error != nil { return nil, dr.Error @@ -222,22 +222,22 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) }) })) - remux.Route(r, "GET", "/keys", remux.JSONHandler(func(r *http.Request) (interface{}, error) { + remux.Route(r, "GET", "/credentials", remux.JSONHandler(func(r *http.Request) (interface{}, error) { callingUserID := middleware.UserID(r.Context()) - return a.getKeys(callingUserID, bridge) + return a.getCredentials(callingUserID, bridge) })) - remux.Route(r, "DELETE", "/key/{credentialName}", remux.JSONHandler(func(r *http.Request) (interface{}, error) { + remux.Route(r, "DELETE", "/credential/{credentialName}", remux.JSONHandler(func(r *http.Request) (interface{}, error) { callingUserID := middleware.UserID(r.Context()) dr := remux.DissectJSONRequest(r) credentialName := dr.FromURL("credentialName").Required().AsString() if dr.Error != nil { return nil, dr.Error } - return nil, a.deleteKey(callingUserID, credentialName, bridge) + return nil, a.deleteCredential(callingUserID, credentialName, bridge) })) - remux.Route(r, "POST", "/key/add/begin", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + remux.Route(r, "POST", "/credential/add/begin", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { remux.JSONHandler(func(r *http.Request) (interface{}, error) { auth, err := bridge.FindUserAuthByContext(r.Context()) if err != nil { @@ -254,7 +254,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) Username: auth.Username, CredentialName: credentialName, UserID: auth.UserID, - RegistrationType: AddKey, + RegistrationType: AddCredential, } creds, err := a.getExistingCredentials(auth) @@ -267,7 +267,7 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) }).ServeHTTP(w, r) })) - remux.Route(r, "POST", "/key/add/finish", remux.JSONHandler(func(r *http.Request) (interface{}, error) { + remux.Route(r, "POST", "/credential/add/finish", remux.JSONHandler(func(r *http.Request) (interface{}, error) { _, encodedCreds, err := a.validateRegistrationComplete(r, bridge) if err != nil { return nil, backend.WrapError("Unable to validate registration data", err) @@ -280,18 +280,18 @@ func (a WebAuthn) BindRoutes(r *mux.Router, bridge authschemes.AShirtAuthBridge) userAuth.JSONData = helpers.Ptr(string(encodedCreds)) err = bridge.UpdateAuthForUser(userAuth) if err != nil { - return nil, backend.WrapError("Unable to update keys", err) + return nil, backend.WrapError("Unable to update credentials", err) } - // We might want to return a full list of keys. TODO: check if we want that + // We might want to return a full list of credentials. TODO: check if we want that return nil, nil })) } -func (a WebAuthn) getKeys(userID int64, bridge authschemes.AShirtAuthBridge) (*ListKeysOutput, error) { +func (a WebAuthn) getCredentials(userID int64, bridge authschemes.AShirtAuthBridge) (*ListCredentialsOutput, error) { auth, err := bridge.FindUserAuthByUserID(userID) if err != nil { - return nil, backend.WrapError("Unable to get keys", err) + return nil, backend.WrapError("Unable to get credentials", err) } webauthRawCreds := []byte(*auth.JSONData) @@ -300,17 +300,17 @@ func (a WebAuthn) getKeys(userID int64, bridge authschemes.AShirtAuthBridge) (*L return nil, backend.WebauthnLoginError(err, "Unable to parse webauthn credentials") } - results := helpers.Map(creds, func(cred AShirtWebauthnCredential) KeyEntry { - return KeyEntry{ + results := helpers.Map(creds, func(cred AShirtWebauthnCredential) CredentialEntry { + return CredentialEntry{ CredentialName: cred.CredentialName, - DateCreated: cred.KeyCreatedDate, + DateCreated: cred.CredentialCreatedDate, } }) - output := ListKeysOutput{results} + output := ListCredentialsOutput{results} return &output, nil } -func (a WebAuthn) deleteKey(userID int64, credentialName string, bridge authschemes.AShirtAuthBridge) error { +func (a WebAuthn) deleteCredential(userID int64, credentialName string, bridge authschemes.AShirtAuthBridge) error { auth, err := bridge.FindUserAuthByUserID(userID) if err != nil { return backend.WrapError("Unable to find user", err) @@ -327,7 +327,7 @@ func (a WebAuthn) deleteKey(userID int64, credentialName string, bridge authsche }) encodedCreds, err := json.Marshal(results) if err != nil { - return backend.WrapError("Unable to delete key", err) + return backend.WrapError("Unable to delete credential", err) } auth.JSONData = helpers.Ptr(string(encodedCreds)) @@ -338,12 +338,12 @@ func (a WebAuthn) deleteKey(userID int64, credentialName string, bridge authsche func (a WebAuthn) beginRegistration(w http.ResponseWriter, r *http.Request, bridge authschemes.AShirtAuthBridge, info WebAuthnRegistrationInfo) (*protocol.CredentialCreation, error) { var user webauthnUser - if info.RegistrationType == CreateKey { + if info.RegistrationType == CreateCredential { user = makeNewWebAuthnUser(info.FirstName, info.LastName, info.Email, info.Username, info.CredentialName) - } else if info.RegistrationType == LinkKey { + } else if info.RegistrationType == LinkCredential { user = makeLinkingWebAuthnUser(info.UserID, info.Username, info.CredentialName) - } else { // Add Key - user = makeAddKeyWebAuthnUser(info.UserID, info.CredentialName, info.Username, info.ExistingCredentials) + } else { // Add Credential + user = makeAddCredentialWebAuthnUser(info.UserID, info.CredentialName, info.Username, info.ExistingCredentials) } credExcludeList := make([]protocol.CredentialDescriptor, len(user.Credentials)) @@ -422,8 +422,8 @@ func (a WebAuthn) validateRegistrationComplete(r *http.Request, bridge authschem } data.UserData.Credentials = append(data.UserData.Credentials, wrapCredential(*cred, AShirtWebauthnExtension{ - CredentialName: data.UserData.CredentialName, - KeyCreatedDate: data.UserData.KeyCreatedDate, + CredentialName: data.UserData.CredentialName, + CredentialCreatedDate: data.UserData.CredentialCreatedDate, })) encodedCreds, err := json.Marshal(data.UserData.Credentials) diff --git a/backend/authschemes/webauthn/webauthnuser.go b/backend/authschemes/webauthn/webauthnuser.go index 4cdae59d0..79008099c 100644 --- a/backend/authschemes/webauthn/webauthnuser.go +++ b/backend/authschemes/webauthn/webauthnuser.go @@ -11,41 +11,41 @@ import ( ) type webauthnUser struct { - UserID []byte - AuthnID []byte - UserName string - IconURL string - Credentials []AShirtWebauthnCredential - FirstName string - LastName string - Email string - CredentialName string - KeyCreatedDate time.Time + UserID []byte + AuthnID []byte + UserName string + IconURL string + Credentials []AShirtWebauthnCredential + FirstName string + LastName string + Email string + CredentialName string + CredentialCreatedDate time.Time } func makeNewWebAuthnUser(firstName, lastName, email, username, credentialName string) webauthnUser { return webauthnUser{ - AuthnID: []byte(uuid.New().String()), - UserName: username, - FirstName: firstName, - LastName: lastName, - Email: email, - CredentialName: credentialName, - KeyCreatedDate: time.Now(), + AuthnID: []byte(uuid.New().String()), + UserName: username, + FirstName: firstName, + LastName: lastName, + Email: email, + CredentialName: credentialName, + CredentialCreatedDate: time.Now(), } } func makeLinkingWebAuthnUser(userID int64, username, credentialName string) webauthnUser { return webauthnUser{ - UserID: i64ToByteSlice(userID), - AuthnID: []byte(uuid.New().String()), - UserName: username, - CredentialName: credentialName, - KeyCreatedDate: time.Now(), + UserID: i64ToByteSlice(userID), + AuthnID: []byte(uuid.New().String()), + UserName: username, + CredentialName: credentialName, + CredentialCreatedDate: time.Now(), } } -func makeAddKeyWebAuthnUser(userID int64, username, credentialName string, creds []AShirtWebauthnCredential) webauthnUser { +func makeAddCredentialWebAuthnUser(userID int64, username, credentialName string, creds []AShirtWebauthnCredential) webauthnUser { user := makeLinkingWebAuthnUser(userID, username, credentialName) user.Credentials = creds return user diff --git a/frontend/src/authschemes/webauthn/services.ts b/frontend/src/authschemes/webauthn/services.ts index c50b7cea9..2f9260168 100644 --- a/frontend/src/authschemes/webauthn/services.ts +++ b/frontend/src/authschemes/webauthn/services.ts @@ -5,8 +5,8 @@ import req from 'src/services/data_sources/backend/request_helper' import { CompletedLoginChallenge, - KeyEntry, - KeyList, + CredentialEntry, + CredentialList, ProvidedCredentialCreationOptions, ProvidedCredentialRequestOptions, WebAuthNRegisterConfirmation, @@ -47,28 +47,28 @@ export async function finishLinking(i: WebAuthNRegisterConfirmation) { return await req('POST', '/auth/webauthn/link/finish', i) } -export async function beginAddKey(i: { +export async function beginAddCredential(i: { credentialName: string }): Promise { - return await req('POST', '/auth/webauthn/key/add/begin', i) + return await req('POST', '/auth/webauthn/credential/add/begin', i) } -export async function finishAddKey(i: WebAuthNRegisterConfirmation) { - return await req('POST', '/auth/webauthn/key/add/finish', i) +export async function finishAddCredential(i: WebAuthNRegisterConfirmation) { + return await req('POST', '/auth/webauthn/credential/add/finish', i) } -export async function listWebauthnKeys(): Promise { - const data: KeyList = await req('GET', '/auth/webauthn/keys') +export async function listWebauthnCredentials(): Promise { + const data: CredentialList = await req('GET', '/auth/webauthn/credentials') return { - keys: data.keys.map((key: KeyEntry) => ({ - ...key, - dateCreated: new Date(key.dateCreated) + credentials: data.credentials.map((credential: CredentialEntry) => ({ + ...credential, + dateCreated: new Date(credential.dateCreated) })) } } -export async function deleteWebauthnKey(i: { credentialName: string }): Promise { - return await req('DELETE', `/auth/webauthn/key/${i.credentialName}`) +export async function deleteWebauthnCredential(i: { credentialName: string }): Promise { + return await req('DELETE', `/auth/webauthn/credential/${i.credentialName}`) } diff --git a/frontend/src/authschemes/webauthn/settings/index.tsx b/frontend/src/authschemes/webauthn/settings/index.tsx index 1dd9a1dbc..1a9bae8f9 100644 --- a/frontend/src/authschemes/webauthn/settings/index.tsx +++ b/frontend/src/authschemes/webauthn/settings/index.tsx @@ -9,7 +9,7 @@ import SettingsSection from 'src/components/settings_section' import classnames from 'classnames/bind' import { useForm, useFormField } from 'src/helpers/use_form' import { renderModals, useModal, useWiredData } from 'src/helpers' -import { beginAddKey, deleteWebauthnKey, finishAddKey, listWebauthnKeys } from '../services' +import { beginAddCredential, deleteWebauthnCredential, finishAddCredential, listWebauthnCredentials } from '../services' import Table from 'src/components/table' import Button from 'src/components/button' import { BuildReloadBus } from 'src/helpers/reload_bus' @@ -26,33 +26,33 @@ export default (props: { }) => { const bus = BuildReloadBus() return ( - - - + + + ) } -const KeyList = (props: { +const CredentialList = (props: { onReload: (listener: () => void) => void offReload: (listener: () => void) => void }) => { - const wiredKeys = useWiredData(listWebauthnKeys) + const wiredCredentials = useWiredData(listWebauthnCredentials) React.useEffect(() => { - props.onReload(wiredKeys.reload) - return () => { props.offReload(wiredKeys.reload) } + props.onReload(wiredCredentials.reload) + return () => { props.offReload(wiredCredentials.reload) } }) - const deleteModal = useModal<{ credentialName: string }>(mProps => , wiredKeys.reload) + const deleteModal = useModal<{ credentialName: string }>(mProps => , wiredCredentials.reload) return (<> - {wiredKeys.render(data => { + {wiredCredentials.render(data => { return (
- {data.keys.map(keyEntry => { - const { credentialName, dateCreated } = keyEntry + {data.credentials.map(credentialEntry => { + const { credentialName, dateCreated } = credentialEntry return ( @@ -75,22 +75,22 @@ const KeyList = (props: { ) } -const AddKeyButton = (props: { +const AddCredentialButton = (props: { requestReload: () => void }) => { const createModal = useModal(mProps => ( - + ), props.requestReload) return (
- + {renderModals(createModal)}
) } -const AddKeyModal = (props: { +const AddCredentialModal = (props: { onRequestClose: () => void, }) => { const credentialName = useFormField("") @@ -101,7 +101,7 @@ const AddKeyModal = (props: { if (credentialName.value === '') { return Promise.reject(new Error("Credential name must be populated")) } - const reg = await beginAddKey({ + const reg = await beginAddCredential({ credentialName: credentialName.value, }) const credOptions = convertToCredentialCreationOptions(reg) @@ -111,16 +111,16 @@ const AddKeyModal = (props: { if (signed == null || signed.type != 'public-key') { throw new Error("WebAuthn is not supported") } - const pubKeyCred = signed as PublicKeyCredential - const pubKeyResponse = pubKeyCred.response as AuthenticatorAttestationResponse + const pubCredential = signed as PublicKeyCredential + const pubCredentialResponse = pubCredential.response as AuthenticatorAttestationResponse - await finishAddKey({ + await finishAddCredential({ type: 'public-key', - id: pubKeyCred.id, - rawId: encodeAsB64(pubKeyCred.rawId), + id: pubCredential.id, + rawId: encodeAsB64(pubCredential.rawId), response: { - attestationObject: encodeAsB64(pubKeyResponse.attestationObject), - clientDataJSON: encodeAsB64(pubKeyResponse.clientDataJSON), + attestationObject: encodeAsB64(pubCredentialResponse.attestationObject), + clientDataJSON: encodeAsB64(pubCredentialResponse.clientDataJSON), }, }) }, @@ -129,7 +129,7 @@ const AddKeyModal = (props: { return ( void, }) => ( deleteWebauthnKey({ credentialName: props.credentialName })} + handleSubmit={() => deleteWebauthnCredential({ credentialName: props.credentialName })} onRequestClose={props.onRequestClose} /> ) diff --git a/frontend/src/authschemes/webauthn/settings/stylesheet.styl b/frontend/src/authschemes/webauthn/settings/stylesheet.styl index 751982f7e..c258f1130 100644 --- a/frontend/src/authschemes/webauthn/settings/stylesheet.styl +++ b/frontend/src/authschemes/webauthn/settings/stylesheet.styl @@ -3,13 +3,13 @@ .header margin-bottom: 10px -.user-key +.user-credential background: $darker-background padding: 1px 5px margin: 0 1px border-radius: 3px box-shadow: 0 0 0 1px rgba(#000, 0.5) -.security-keys-section +.security-credentials-section * margin-bottom: 5px diff --git a/frontend/src/authschemes/webauthn/types.ts b/frontend/src/authschemes/webauthn/types.ts index b93e89e0d..5ab21dfbf 100644 --- a/frontend/src/authschemes/webauthn/types.ts +++ b/frontend/src/authschemes/webauthn/types.ts @@ -56,11 +56,11 @@ export type CompletedLoginChallenge = { } } -export type KeyList = { - keys: Array +export type CredentialList = { + credentials: Array } -export type KeyEntry = { +export type CredentialEntry = { credentialName: string dateCreated: Date }
{credentialName}