Files
photoprism/internal/api/oauth_authorize.go
Michael Mayer 7dff5511bc API: Refactor OAuth2 and OIDC endpoints #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-06-27 10:16:12 +02:00

47 lines
1.2 KiB
Go

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/get"
"github.com/photoprism/photoprism/pkg/authn"
"github.com/photoprism/photoprism/pkg/header"
"github.com/photoprism/photoprism/pkg/i18n"
)
// OAuthAuthorize is a starting point for browser-based OpenID Connect flows.
//
// GET /api/v1/oauth/authorize
func OAuthAuthorize(router *gin.RouterGroup) {
router.GET("/oauth/authorize", func(c *gin.Context) {
// Prevent CDNs from caching this endpoint.
if header.IsCdn(c.Request) {
AbortNotFound(c)
return
}
// Disable caching of responses.
c.Header(header.CacheControl, header.CacheControlNoStore)
// Get client IP address for logs and rate limiting checks.
clientIp := ClientIP(c)
actor := "unknown client"
action := "authorize"
// Abort if running in public mode.
if get.Config().Public() {
event.AuditErr([]string{clientIp, "oauth2", actor, action, authn.ErrDisabledInPublicMode.Error()})
Abort(c, http.StatusForbidden, i18n.ErrForbidden)
return
}
// TODO
// Send response.
c.JSON(http.StatusMethodNotAllowed, gin.H{"status": StatusFailed})
})
}