summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-06-07 16:21:57 +0200
committerLibravatar GitHub <noreply@github.com>2024-06-07 15:21:57 +0100
commitce3b8aacf73b841887f3eec631851d086a7578f1 (patch)
tree3c0ab7a93ffddc952e39c33140414106019e39e8 /internal
parent[chore] Update WASM go-sqlite3 to v0.16.1 (#2976) (diff)
downloadgotosocial-ce3b8aacf73b841887f3eec631851d086a7578f1.tar.xz
[chore] Warn about email/password change when using OIDC (#2975)
* [chore] Warn about email/password change when using OIDC * go fmt
Diffstat (limited to 'internal')
-rw-r--r--internal/api/client/user/passwordchange.go11
-rw-r--r--internal/api/model/instancev1.go2
-rw-r--r--internal/api/model/instancev2.go2
-rw-r--r--internal/config/helpers.gen.go3
-rw-r--r--internal/typeutils/internaltofrontend.go2
5 files changed, 18 insertions, 2 deletions
diff --git a/internal/api/client/user/passwordchange.go b/internal/api/client/user/passwordchange.go
index c2928e9e5..df9f5b0c8 100644
--- a/internal/api/client/user/passwordchange.go
+++ b/internal/api/client/user/passwordchange.go
@@ -24,10 +24,13 @@ import (
"github.com/gin-gonic/gin"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
+const OIDCPasswordHelp = "password change request cannot be processed by GoToSocial as this instance is running with OIDC enabled; you must change password using your OIDC provider"
+
// PasswordChangePOSTHandler swagger:operation POST /api/v1/user/password_change userPasswordChange
//
// Change the password of authenticated user.
@@ -62,6 +65,8 @@ import (
// description: forbidden
// '406':
// description: not acceptable
+// '422':
+// description: unprocessable request because instance is running with OIDC backend
// '500':
// description: internal error
func (m *Module) PasswordChangePOSTHandler(c *gin.Context) {
@@ -76,6 +81,12 @@ func (m *Module) PasswordChangePOSTHandler(c *gin.Context) {
return
}
+ if config.GetOIDCEnabled() {
+ err := errors.New("instance running with OIDC")
+ apiutil.ErrorHandler(c, gtserror.NewErrorUnprocessableEntity(err, OIDCPasswordHelp), m.processor.InstanceGetV1)
+ return
+ }
+
form := &apimodel.PasswordChangeRequest{}
if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
diff --git a/internal/api/model/instancev1.go b/internal/api/model/instancev1.go
index 217edc08c..beb4f430d 100644
--- a/internal/api/model/instancev1.go
+++ b/internal/api/model/instancev1.go
@@ -127,4 +127,6 @@ type InstanceV1Configuration struct {
Accounts InstanceConfigurationAccounts `json:"accounts"`
// Instance configuration pertaining to emojis.
Emojis InstanceConfigurationEmojis `json:"emojis"`
+ // True if instance is running with OIDC as auth/identity backend, else omitted.
+ OIDCEnabled bool `json:"oidc_enabled,omitempty"`
}
diff --git a/internal/api/model/instancev2.go b/internal/api/model/instancev2.go
index a1b98ea65..fce801117 100644
--- a/internal/api/model/instancev2.go
+++ b/internal/api/model/instancev2.go
@@ -163,6 +163,8 @@ type InstanceV2Configuration struct {
Translation InstanceV2ConfigurationTranslation `json:"translation"`
// Instance configuration pertaining to emojis.
Emojis InstanceConfigurationEmojis `json:"emojis"`
+ // True if instance is running with OIDC as auth/identity backend, else omitted.
+ OIDCEnabled bool `json:"oidc_enabled,omitempty"`
}
// Information about registering for this instance.
diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go
index edfe96e57..71a77e753 100644
--- a/internal/config/helpers.gen.go
+++ b/internal/config/helpers.gen.go
@@ -2,7 +2,7 @@
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
-//
+//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
@@ -4074,4 +4074,3 @@ func GetRequestIDHeader() string { return global.GetRequestIDHeader() }
// SetRequestIDHeader safely sets the value for global configuration 'RequestIDHeader' field
func SetRequestIDHeader(v string) { global.SetRequestIDHeader(v) }
-
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index f3c027316..80f083ef1 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -1328,6 +1328,7 @@ func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Ins
instance.Configuration.Accounts.MaxFeaturedTags = instanceAccountsMaxFeaturedTags
instance.Configuration.Accounts.MaxProfileFields = instanceAccountsMaxProfileFields
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize())
+ instance.Configuration.OIDCEnabled = config.GetOIDCEnabled()
// URLs
instance.URLs.StreamingAPI = "wss://" + i.Domain
@@ -1467,6 +1468,7 @@ func (c *Converter) InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Ins
instance.Configuration.Accounts.MaxFeaturedTags = instanceAccountsMaxFeaturedTags
instance.Configuration.Accounts.MaxProfileFields = instanceAccountsMaxProfileFields
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize())
+ instance.Configuration.OIDCEnabled = config.GetOIDCEnabled()
// registrations
instance.Registrations.Enabled = config.GetAccountsRegistrationOpen()