API: Add additional fields to label and subject edit forms #383 #3168

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-01-17 02:55:07 +01:00
parent d786a8225d
commit 0ada8d1095
99 changed files with 1241 additions and 1101 deletions

View File

@@ -47,24 +47,24 @@ func OAuthToken(router *gin.RouterGroup) {
c.Header(header.CacheControl, header.CacheControlNoStore)
// Token create request form.
var f form.OAuthCreateToken
var frm form.OAuthCreateToken
var sess *entity.Session
var client *entity.Client
var err error
// Allow authentication with basic auth and form values.
if clientId, clientSecret, _ := header.BasicAuth(c); clientId != "" && clientSecret != "" {
f.GrantType = authn.GrantClientCredentials
f.ClientID = clientId
f.ClientSecret = clientSecret
} else if err = c.ShouldBind(&f); err != nil {
frm.GrantType = authn.GrantClientCredentials
frm.ClientID = clientId
frm.ClientSecret = clientSecret
} else if err = c.ShouldBind(&frm); err != nil {
event.AuditWarn([]string{clientIp, "oauth2", actor, action, "%s"}, err)
AbortBadRequest(c)
return
}
// Check the credentials for completeness and the correct format.
if err = f.Validate(); err != nil {
if err = frm.Validate(); err != nil {
event.AuditWarn([]string{clientIp, "oauth2", actor, action, "%s"}, err)
AbortInvalidCredentials(c)
return
@@ -79,19 +79,19 @@ func OAuthToken(router *gin.RouterGroup) {
return
}
if f.ClientID != "" {
actor = fmt.Sprintf("client %s", clean.Log(f.ClientID))
} else if f.Username != "" {
actor = fmt.Sprintf("user %s", clean.Log(f.Username))
} else if f.GrantType == authn.GrantPassword {
if frm.ClientID != "" {
actor = fmt.Sprintf("client %s", clean.Log(frm.ClientID))
} else if frm.Username != "" {
actor = fmt.Sprintf("user %s", clean.Log(frm.Username))
} else if frm.GrantType == authn.GrantPassword {
actor = "unknown user"
}
// Create a new session (access token) based on the grant type specified in the request.
switch f.GrantType {
switch frm.GrantType {
case authn.GrantClientCredentials, authn.GrantUndefined:
// Find client with the specified ID.
client = entity.FindClientByUID(f.ClientID)
client = entity.FindClientByUID(frm.ClientID)
// Check if a client has been found, it is enabled, and the credentials are valid.
if client == nil {
@@ -106,7 +106,7 @@ func OAuthToken(router *gin.RouterGroup) {
event.AuditWarn([]string{clientIp, "oauth2", actor, action, "method %s not supported"}, clean.LogQuote(method.String()))
AbortInvalidCredentials(c)
return
} else if client.InvalidSecret(f.ClientSecret) {
} else if client.InvalidSecret(frm.ClientSecret) {
event.AuditWarn([]string{clientIp, "oauth2", actor, action, authn.ErrInvalidClientSecret.Error()})
AbortInvalidCredentials(c)
return
@@ -138,7 +138,7 @@ func OAuthToken(router *gin.RouterGroup) {
if s.User().Provider().SupportsPasswordAuthentication() {
loginForm := form.Login{
Username: s.Username(),
Password: f.Password,
Password: frm.Password,
}
authUser, authProvider, authMethod, authErr := entity.Auth(loginForm, nil, c)
@@ -159,12 +159,12 @@ func OAuthToken(router *gin.RouterGroup) {
return
}
f.GrantType = authn.GrantPassword
frm.GrantType = authn.GrantPassword
} else {
f.GrantType = authn.GrantSession
frm.GrantType = authn.GrantSession
}
sess = entity.NewClientSession(f.ClientName, f.ExpiresIn, f.Scope, f.GrantType, s.User())
sess = entity.NewClientSession(frm.ClientName, frm.ExpiresIn, frm.Scope, frm.GrantType, s.User())
// Return the reserved request rate limit tokens after successful authentication.
r.Success()