mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package webauth
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/go-webauthn/webauthn/protocol"
|
||
|
|
"github.com/go-webauthn/webauthn/protocol/webauthncose"
|
||
|
|
"github.com/labstack/echo/v4"
|
||
|
|
"github.com/onsonr/sonr/pkg/common"
|
||
|
|
)
|
||
|
|
|
||
|
|
func buildRegisterOptions(user protocol.UserEntity, blob common.LargeBlob, service protocol.RelyingPartyEntity) protocol.PublicKeyCredentialCreationOptions {
|
||
|
|
return protocol.PublicKeyCredentialCreationOptions{
|
||
|
|
Timeout: 10000,
|
||
|
|
Attestation: protocol.PreferDirectAttestation,
|
||
|
|
AuthenticatorSelection: protocol.AuthenticatorSelection{
|
||
|
|
AuthenticatorAttachment: "platform",
|
||
|
|
ResidentKey: protocol.ResidentKeyRequirementPreferred,
|
||
|
|
UserVerification: "preferred",
|
||
|
|
},
|
||
|
|
RelyingParty: service,
|
||
|
|
User: user,
|
||
|
|
Extensions: protocol.AuthenticationExtensions{
|
||
|
|
"largeBlob": blob,
|
||
|
|
},
|
||
|
|
Parameters: []protocol.CredentialParameter{
|
||
|
|
{
|
||
|
|
Type: "public-key",
|
||
|
|
Algorithm: webauthncose.AlgES256,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
Type: "public-key",
|
||
|
|
Algorithm: webauthncose.AlgES256K,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
Type: "public-key",
|
||
|
|
Algorithm: webauthncose.AlgEdDSA,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildLargeBlob(userKeyshareJSON string) common.LargeBlob {
|
||
|
|
return common.LargeBlob{
|
||
|
|
Support: "required",
|
||
|
|
Write: userKeyshareJSON,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildUserEntity(userAddress string, userHandle string) protocol.UserEntity {
|
||
|
|
return protocol.UserEntity{
|
||
|
|
ID: userAddress,
|
||
|
|
DisplayName: userHandle,
|
||
|
|
CredentialEntity: protocol.CredentialEntity{
|
||
|
|
Name: userAddress,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildServiceEntity(c echo.Context) protocol.RelyingPartyEntity {
|
||
|
|
return protocol.RelyingPartyEntity{
|
||
|
|
CredentialEntity: protocol.CredentialEntity{
|
||
|
|
Name: "Sonr.ID",
|
||
|
|
},
|
||
|
|
ID: c.Request().Host,
|
||
|
|
}
|
||
|
|
}
|