Skip to content

Commit 5f23372

Browse files
committed
adds env var GOTIFY_OIDC_IDP_NAME with default "OIDC"
variable is used in the UI for button labels at login and elevation forms
1 parent c27a381 commit 5f23372

11 files changed

Lines changed: 52 additions & 10 deletions

File tree

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type OIDC struct {
6868
AutoRegister bool
6969
LinkByUsername bool
7070
Scopes []string
71+
IDPName string
7172
}
7273

7374
type Configuration struct {
@@ -115,6 +116,7 @@ func Get() (*Configuration, []FutureLog) {
115116
UsernameClaim: "preferred_username",
116117
AutoRegister: true,
117118
Scopes: []string{"openid", "profile", "email"},
119+
IDPName: "OIDC",
118120
},
119121
}
120122

@@ -177,6 +179,7 @@ func Get() (*Configuration, []FutureLog) {
177179
add(parseBool(&c.OIDC.AutoRegister, EnvOIDCAutoRegister))
178180
add(parseBool(&c.OIDC.LinkByUsername, EnvOIDCLinkByUsername))
179181
add(parseList(&c.OIDC.Scopes, EnvOIDCScopes))
182+
add(parseString(&c.OIDC.IDPName, EnvOIDCIDPName))
180183

181184
add(parseString(&c.NoColor, EnvNoColor))
182185

config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestConfigEnv(t *testing.T) {
2020
os.Setenv("GOTIFY_SERVER_CORS_ALLOWMETHODS", "GET,POST")
2121
os.Setenv("GOTIFY_SERVER_CORS_ALLOWHEADERS", "Authorization,content-type")
2222
os.Setenv("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS", ".+.example.com,otherdomain.com")
23+
os.Setenv("GOTIFY_OIDC_IDP_NAME", "Company XYZ SSO")
2324

2425
defer func() {
2526
os.Unsetenv("GOTIFY_DEFAULTUSER_NAME")
@@ -29,6 +30,7 @@ func TestConfigEnv(t *testing.T) {
2930
os.Unsetenv("GOTIFY_SERVER_CORS_ALLOWMETHODS")
3031
os.Unsetenv("GOTIFY_SERVER_CORS_ALLOWHEADERS")
3132
os.Unsetenv("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS")
33+
os.Unsetenv("GOTIFY_OIDC_IDP_NAME")
3234
}()
3335

3436
conf, _ := Get()
@@ -41,6 +43,7 @@ func TestConfigEnv(t *testing.T) {
4143
assert.Equal(t, []string{"GET", "POST"}, conf.Server.Cors.AllowMethods)
4244
assert.Equal(t, []string{"Authorization", "content-type"}, conf.Server.Cors.AllowHeaders)
4345
assert.Equal(t, []string{".+.example.com", "otherdomain.com"}, conf.Server.Stream.AllowedOrigins)
46+
assert.Equal(t, "Company XYZ SSO", conf.OIDC.IDPName)
4447
}
4548

4649
func TestFile(t *testing.T) {

config/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ const (
4141
EnvOIDCAutoRegister = "GOTIFY_OIDC_AUTOREGISTER"
4242
EnvOIDCLinkByUsername = "GOTIFY_OIDC_LINK_BY_USERNAME"
4343
EnvOIDCScopes = "GOTIFY_OIDC_SCOPES"
44+
EnvOIDCIDPName = "GOTIFY_OIDC_IDP_NAME"
4445
EnvNoColor = "NOCOLOR"
4546
)

docs/spec.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,8 @@
29402940
"required": [
29412941
"version",
29422942
"register",
2943-
"oidc"
2943+
"oidc",
2944+
"oidcIdpName"
29442945
],
29452946
"properties": {
29462947
"oidc": {
@@ -2949,6 +2950,12 @@
29492950
"x-go-name": "Oidc",
29502951
"example": true
29512952
},
2953+
"oidcIdpName": {
2954+
"description": "Name of the OIDC identity provider.",
2955+
"type": "string",
2956+
"x-go-name": "OIDCIDPName",
2957+
"example": "OIDC"
2958+
},
29522959
"register": {
29532960
"description": "If registration is enabled.",
29542961
"type": "boolean",

gotify-server.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@
224224
# Type: text-list
225225
# GOTIFY_OIDC_SCOPES=openid,profile,email
226226

227+
# Name of the OIDC identity provider displayed in the login and elevation UI.
228+
# Only used if GOTIFY_OIDC_ENABLED is true. Defaults to OIDC.
229+
#
230+
# Type: text
231+
# Example: Company XYZ SSO
232+
# GOTIFY_OIDC_IDP_NAME=OIDC
233+
227234
# Database driver to use. For mysql and postgres the target database must
228235
# already exist and the configured user must have sufficient permissions.
229236
#

model/gotifyinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ type GotifyInfo struct {
1919
// required: true
2020
// example: true
2121
Oidc bool `json:"oidc"`
22+
// Name of the OIDC identity provider.
23+
//
24+
// required: true
25+
// example: OIDC
26+
OIDCIDPName string `json:"oidcIdpName"`
2227
}

router/router.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
118118
userChangeNotifier.OnUserDeleted(pluginManager.RemoveUser)
119119
userChangeNotifier.OnUserAdded(pluginManager.InitializeForUserID)
120120

121-
ui.Register(g, *vInfo, conf.Registration, conf.OIDC.Enabled)
121+
ui.Register(g, *vInfo, conf.Registration, conf.OIDC.Enabled, conf.OIDC.IDPName)
122122

123123
if conf.OIDC.Enabled {
124124
oidcHandler := api.NewOIDC(conf, db, userChangeNotifier)
@@ -189,7 +189,12 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
189189
// schema:
190190
// $ref: "#/definitions/GotifyInfo"
191191
g.GET("gotifyinfo", func(ctx *gin.Context) {
192-
ctx.JSON(200, &model.GotifyInfo{Version: vInfo.Version, Oidc: conf.OIDC.Enabled, Register: conf.Registration})
192+
ctx.JSON(200, &model.GotifyInfo{
193+
Version: vInfo.Version,
194+
Oidc: conf.OIDC.Enabled,
195+
Register: conf.Registration,
196+
OIDCIDPName: conf.OIDC.IDPName,
197+
})
193198
})
194199

195200
g.Group("/").Use(authentication.RequireApplicationOrClient).POST("/message", messageHandler.CreateMessage)

ui/serve.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ import (
1616
var box embed.FS
1717

1818
type uiConfig struct {
19-
Register bool `json:"register"`
20-
Version model.VersionInfo `json:"version"`
21-
OIDC bool `json:"oidc"`
19+
Register bool `json:"register"`
20+
Version model.VersionInfo `json:"version"`
21+
OIDC bool `json:"oidc"`
22+
OIDCIDPName string `json:"oidcIdpName"`
2223
}
2324

2425
// Register registers the ui on the root path.
25-
func Register(r *gin.Engine, version model.VersionInfo, register, oidcEnabled bool) {
26-
uiConfigBytes, err := json.Marshal(uiConfig{Version: version, Register: register, OIDC: oidcEnabled})
26+
func Register(r *gin.Engine, version model.VersionInfo, register, oidcEnabled bool, oidcIDPName string) {
27+
uiConfigBytes, err := json.Marshal(uiConfig{
28+
Version: version,
29+
Register: register,
30+
OIDC: oidcEnabled,
31+
OIDCIDPName: oidcIDPName,
32+
})
2733
if err != nil {
2834
panic(err)
2935
}

ui/src/common/ElevationForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ElevationForm = observer(() => {
1717

1818
const oidcEnabled = config.get('oidc');
1919
const oidcPending = elevateStore.oidcElevatePending;
20+
const oidcIdpName = config.get('oidcIdpName');
2021

2122
const handleLocalElevate = async () => {
2223
try {
@@ -88,7 +89,7 @@ const ElevationForm = observer(() => {
8889
color="primary"
8990
fullWidth
9091
onClick={() => elevateStore.oidcElevate(ElevateDuration)}>
91-
Elevate via OIDC
92+
{`Elevate via ${oidcIdpName}`}
9293
</Button>
9394
</>
9495
)}

ui/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface IConfig {
55
register: boolean;
66
version: IVersion;
77
oidc: boolean;
8+
oidcIdpName: string;
89
}
910

1011
declare global {
@@ -18,6 +19,7 @@ const config: IConfig = {
1819
register: false,
1920
version: {commit: 'unknown', buildDate: 'unknown', version: 'unknown'},
2021
oidc: false,
22+
oidcIdpName: 'OIDC',
2123
...window.config,
2224
};
2325

0 commit comments

Comments
 (0)