mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Modify: create Web Authn instance when needed
This commit is contained in:
@@ -2,26 +2,15 @@ package authn
|
||||
|
||||
import (
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"github.com/duo-labs/webauthn/webauthn"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var AuthnInstance *webauthn.WebAuthn
|
||||
var Lock sync.RWMutex
|
||||
|
||||
// Init 初始化webauthn
|
||||
func Init() {
|
||||
Lock.Lock()
|
||||
defer Lock.Unlock()
|
||||
var err error
|
||||
// NewAuthnInstance 新建Authn实例
|
||||
func NewAuthnInstance() (*webauthn.WebAuthn, error) {
|
||||
base := model.GetSiteURL()
|
||||
AuthnInstance, err = webauthn.New(&webauthn.Config{
|
||||
return webauthn.New(&webauthn.Config{
|
||||
RPDisplayName: model.GetSettingByName("siteName"), // Display Name for your site
|
||||
RPID: base.Hostname(), // Generally the FQDN for your site
|
||||
RPOrigin: base.String(), // The origin URL for WebAuthn requests
|
||||
})
|
||||
if err != nil {
|
||||
util.Log().Error("无法初始化WebAuthn, %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ func TestInit(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
cache.Set("setting_siteURL", "http://cloudreve.org", 0)
|
||||
cache.Set("setting_siteName", "Cloudreve", 0)
|
||||
asserts.NotPanics(func() {
|
||||
Init()
|
||||
})
|
||||
asserts.NotNil(AuthnInstance)
|
||||
res, err := NewAuthnInstance()
|
||||
asserts.NotNil(res)
|
||||
asserts.NoError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user