feat: initial commit
This commit is contained in:
29
internal/webauthn/provider.go
Normal file
29
internal/webauthn/provider.go
Normal file
@ -0,0 +1,29 @@
|
||||
package webauthn
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/service"
|
||||
)
|
||||
|
||||
type Config = webauthn.Config
|
||||
type TimeoutsConfig = webauthn.TimeoutsConfig
|
||||
type TimeoutConfig = webauthn.TimeoutConfig
|
||||
type LoginOption = webauthn.LoginOption
|
||||
type SessionData = webauthn.SessionData
|
||||
|
||||
var WithAllowedCredentials = webauthn.WithAllowedCredentials
|
||||
var WithAssertionExtensions = webauthn.WithAssertionExtensions
|
||||
var WithUserVerification = webauthn.WithUserVerification
|
||||
var WithAppIdExtension = webauthn.WithAppIdExtension
|
||||
|
||||
func ServiceProvider(config *Config) service.Provider {
|
||||
webauthn, err := webauthn.New(config)
|
||||
|
||||
return func(ctn *service.Container) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
return webauthn, nil
|
||||
}
|
||||
}
|
34
internal/webauthn/service.go
Normal file
34
internal/webauthn/service.go
Normal file
@ -0,0 +1,34 @@
|
||||
package webauthn
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/service"
|
||||
)
|
||||
|
||||
const ServiceName service.Name = "webauthn"
|
||||
|
||||
// From retrieves the webauthn service in the given container
|
||||
func From(container *service.Container) (*webauthn.WebAuthn, error) {
|
||||
service, err := container.Service(ServiceName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
||||
}
|
||||
|
||||
srv, ok := service.(*webauthn.WebAuthn)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
||||
}
|
||||
|
||||
return srv, nil
|
||||
}
|
||||
|
||||
// Must retrieves the config service in the given container or panic otherwise
|
||||
func Must(container *service.Container) *webauthn.WebAuthn {
|
||||
srv, err := From(container)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return srv
|
||||
}
|
Reference in New Issue
Block a user