Auth: Make OIDC initialization more resilient #782
This commit is contained in:
parent
1ae85a0e04
commit
24f6041a76
2 changed files with 15 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue