Cloudreve/pkg/authn/auth.go

28 lines
732 B
Go
Raw Normal View History

2019-12-08 22:17:36 +08:00
package authn
import (
2020-02-21 10:08:47 +08:00
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/util"
2019-12-08 22:17:36 +08:00
"github.com/duo-labs/webauthn/webauthn"
2020-02-23 15:33:53 +08:00
"sync"
2019-12-08 22:17:36 +08:00
)
var AuthnInstance *webauthn.WebAuthn
2020-02-23 15:33:53 +08:00
var Lock sync.RWMutex
2019-12-08 22:17:36 +08:00
2020-02-21 10:08:47 +08:00
// Init 初始化webauthn
2019-12-08 22:17:36 +08:00
func Init() {
2020-02-23 15:33:53 +08:00
Lock.Lock()
defer Lock.Unlock()
2019-12-08 22:17:36 +08:00
var err error
2020-02-21 10:08:47 +08:00
base := model.GetSiteURL()
AuthnInstance, err = webauthn.New(&webauthn.Config{
2020-02-21 10:08:47 +08:00
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
2019-12-08 22:17:36 +08:00
})
if err != nil {
2020-02-21 10:08:47 +08:00
util.Log().Error("无法初始化WebAuthn, %s", err)
2019-12-08 22:17:36 +08:00
}
}