@@ -6,7 +6,7 @@ package auth
66
77import (
88 "context"
9- "encoding/base64 "
9+ "encoding/base32 "
1010 "fmt"
1111 "strings"
1212
@@ -94,7 +94,7 @@ type WebAuthnCredentialList []*WebAuthnCredential
9494func (list WebAuthnCredentialList ) ToCredentials () []webauthn.Credential {
9595 creds := make ([]webauthn.Credential , 0 , len (list ))
9696 for _ , cred := range list {
97- credID , _ := base64 . RawStdEncoding .DecodeString (cred .CredentialID )
97+ credID , _ := base32 . HexEncoding .DecodeString (cred .CredentialID )
9898 creds = append (creds , webauthn.Credential {
9999 ID : credID ,
100100 PublicKey : cred .PublicKey ,
@@ -164,13 +164,13 @@ func HasWebAuthnRegistrationsByUID(uid int64) (bool, error) {
164164}
165165
166166// GetWebAuthnCredentialByCredID returns WebAuthn credential by credential ID
167- func GetWebAuthnCredentialByCredID (credID string ) (* WebAuthnCredential , error ) {
168- return getWebAuthnCredentialByCredID (db .DefaultContext , credID )
167+ func GetWebAuthnCredentialByCredID (userID int64 , credID string ) (* WebAuthnCredential , error ) {
168+ return getWebAuthnCredentialByCredID (db .DefaultContext , userID , credID )
169169}
170170
171- func getWebAuthnCredentialByCredID (ctx context.Context , credID string ) (* WebAuthnCredential , error ) {
171+ func getWebAuthnCredentialByCredID (ctx context.Context , userID int64 , credID string ) (* WebAuthnCredential , error ) {
172172 cred := new (WebAuthnCredential )
173- if found , err := db .GetEngine (ctx ).Where ("credential_id = ?" , credID ).Get (cred ); err != nil {
173+ if found , err := db .GetEngine (ctx ).Where ("user_id = ? AND credential_id = ?" , userID , credID ).Get (cred ); err != nil {
174174 return nil , err
175175 } else if ! found {
176176 return nil , ErrWebAuthnCredentialNotExist {CredentialID : credID }
@@ -187,7 +187,7 @@ func createCredential(ctx context.Context, userID int64, name string, cred *weba
187187 c := & WebAuthnCredential {
188188 UserID : userID ,
189189 Name : name ,
190- CredentialID : base64 . RawStdEncoding .EncodeToString (cred .ID ),
190+ CredentialID : base32 . HexEncoding .EncodeToString (cred .ID ),
191191 PublicKey : cred .PublicKey ,
192192 AttestationType : cred .AttestationType ,
193193 AAGUID : cred .Authenticator .AAGUID ,
0 commit comments