mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-11 16:24:11 +01:00
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/photoprism/photoprism/internal/event"
|
|
"github.com/photoprism/photoprism/internal/photoprism/get"
|
|
"github.com/photoprism/photoprism/pkg/authn"
|
|
"github.com/photoprism/photoprism/pkg/http/header"
|
|
"github.com/photoprism/photoprism/pkg/i18n"
|
|
)
|
|
|
|
// OAuthUserinfo should return information about the authenticated user,
|
|
// see https://github.com/photoprism/photoprism/issues/4369.
|
|
//
|
|
// @Summary OAuth2 userinfo endpoint (not implemented)
|
|
// @Id OAuthUserinfo
|
|
// @Tags Authentication
|
|
// @Produce json
|
|
// @Failure 405 {object} i18n.Response
|
|
// @Router /api/v1/oauth/userinfo [get]
|
|
func OAuthUserinfo(router *gin.RouterGroup) {
|
|
router.GET("/oauth/userinfo", 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 := "userinfo"
|
|
|
|
// 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: see https://github.com/photoprism/photoprism/issues/4369
|
|
|
|
// Send response.
|
|
c.JSON(http.StatusMethodNotAllowed, gin.H{"status": StatusFailed})
|
|
})
|
|
}
|