|
@@ -8,6 +8,7 @@ import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"log/slog"
|
|
"log/slog"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "slices"
|
|
|
|
|
|
|
|
"miniflux.app/v2/internal/config"
|
|
"miniflux.app/v2/internal/config"
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
"miniflux.app/v2/internal/http/request"
|
|
@@ -116,6 +117,11 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ groupClaim := config.Opts.Oauth2GroupClaim()
|
|
|
|
|
+ adminGroup := config.Opts.Oauth2AdminGroup()
|
|
|
|
|
+ adminRoleMappingEnabled := provider == "oidc" && groupClaim != "" && adminGroup != ""
|
|
|
|
|
+ isAdmin := adminRoleMappingEnabled && slices.Contains(profile.Groups, adminGroup)
|
|
|
|
|
+
|
|
|
if user == nil {
|
|
if user == nil {
|
|
|
if !config.Opts.IsOAuth2UserCreationAllowed() {
|
|
if !config.Opts.IsOAuth2UserCreationAllowed() {
|
|
|
response.HTMLForbidden(w, r)
|
|
response.HTMLForbidden(w, r)
|
|
@@ -127,7 +133,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- userCreationRequest := &model.UserCreationRequest{Username: profile.Username}
|
|
|
|
|
|
|
+ userCreationRequest := &model.UserCreationRequest{Username: profile.Username, IsAdmin: isAdmin}
|
|
|
authProvider.PopulateUserCreationWithProfileID(userCreationRequest, profile)
|
|
authProvider.PopulateUserCreationWithProfileID(userCreationRequest, profile)
|
|
|
|
|
|
|
|
user, err = h.store.CreateUser(userCreationRequest)
|
|
user, err = h.store.CreateUser(userCreationRequest)
|
|
@@ -145,6 +151,14 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
|
|
|
slog.String("username", user.Username),
|
|
slog.String("username", user.Username),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ if adminRoleMappingEnabled && user.IsAdmin != isAdmin {
|
|
|
|
|
+ user.IsAdmin = isAdmin
|
|
|
|
|
+ if err := h.store.UpdateUser(user); err != nil {
|
|
|
|
|
+ response.HTMLServerError(w, r, err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
h.store.SetLastLogin(user.ID)
|
|
h.store.SetLastLogin(user.ID)
|
|
|
if err := authenticateWebSession(w, r, h.store, user); err != nil {
|
|
if err := authenticateWebSession(w, r, h.store, user); err != nil {
|
|
|
response.HTMLServerError(w, r, err)
|
|
response.HTMLServerError(w, r, err)
|