Auth: Make OIDC initialization more resilient #782

This commit is contained in:
Timo Volkmann 2021-09-20 19:14:57 +02:00
parent 1ae85a0e04
commit 24f6041a76
2 changed files with 15 additions and 6 deletions

View file

@ -18,15 +18,26 @@ func AuthEndpoints(router *gin.RouterGroup) {
log.Debugf("no oidc provider configured. skip mounting endpoints")
return
}
openIdConnect := service.Oidc()
router.GET("/auth/external", func(c *gin.Context) {
openIdConnect := service.Oidc()
if openIdConnect == nil {
AbortFeatureDisabled(c)
return
}
handle := openIdConnect.AuthUrlHandler()
handle(c.Writer, c.Request)
return
})
router.GET(oidc.RedirectPath, func(c *gin.Context) {
openIdConnect := service.Oidc()
if openIdConnect == nil {
AbortFeatureDisabled(c)
return
}
userInfo, err := openIdConnect.CodeExchangeUserInfo(c)
if err != nil {
log.Errorf("%s", err)

View file

@ -1,13 +1,9 @@
package service
import (
"sync"
"github.com/photoprism/photoprism/internal/oidc"
)
var onceOidc sync.Once
func initOidc() {
services.Oidc = oidc.NewClient(
Config().OidcIssuerUrl(),
@ -19,6 +15,8 @@ func initOidc() {
}
func Oidc() *oidc.Client {
onceOidc.Do(initOidc)
if services.Oidc == nil {
initOidc()
}
return services.Oidc
}