mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
API: Refactor OAuth2 and OIDC endpoints #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
46
internal/api/oauth_userinfo.go
Normal file
46
internal/api/oauth_userinfo.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// OAuthUserinfo returns information about the authenticated user.
|
||||
//
|
||||
// GET /api/v1/oauth/userinfo
|
||||
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
|
||||
|
||||
// Send response.
|
||||
c.JSON(http.StatusMethodNotAllowed, gin.H{"status": StatusFailed})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user