Skip to content

Commit ef41eba

Browse files
authored
Merge pull request #1022 from DerDummePunkt/github_991_ux_improvments_configurable_oidc_login_button_text
#991 ux improvements: OIDC Login Label
2 parents aceb5ff + 7723d13 commit ef41eba

13 files changed

Lines changed: 71 additions & 18 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 {
@@ -117,6 +118,7 @@ func Get() (*Configuration, []FutureLog) {
117118
UsernameClaim: "preferred_username",
118119
AutoRegister: true,
119120
Scopes: []string{"openid", "profile", "email"},
121+
IDPName: "OIDC",
120122
},
121123
}
122124

@@ -180,6 +182,7 @@ func Get() (*Configuration, []FutureLog) {
180182
add(parseBool(&c.OIDC.AutoRegister, EnvOIDCAutoRegister))
181183
add(parseBool(&c.OIDC.LinkByUsername, EnvOIDCLinkByUsername))
182184
add(parseList(&c.OIDC.Scopes, EnvOIDCScopes))
185+
add(parseString(&c.OIDC.IDPName, EnvOIDCIDPName))
183186

184187
add(parseString(&c.NoColor, EnvNoColor))
185188

config/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestConfigEnv(t *testing.T) {
2222
t.Setenv("GOTIFY_SERVER_CORS_ALLOWMETHODS", "GET,POST")
2323
t.Setenv("GOTIFY_SERVER_CORS_ALLOWHEADERS", "Authorization,content-type")
2424
t.Setenv("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS", ".+.example.com,otherdomain.com")
25+
t.Setenv("GOTIFY_OIDC_IDP_NAME", "Company XYZ SSO")
2526

2627
conf, _ := Get()
2728
assert.Equal(t, 80, conf.Server.Port, "should use defaults")
@@ -33,6 +34,7 @@ func TestConfigEnv(t *testing.T) {
3334
assert.Equal(t, []string{"GET", "POST"}, conf.Server.Cors.AllowMethods)
3435
assert.Equal(t, []string{"Authorization", "content-type"}, conf.Server.Cors.AllowHeaders)
3536
assert.Equal(t, []string{".+.example.com", "otherdomain.com"}, conf.Server.Stream.AllowedOrigins)
37+
assert.Equal(t, "Company XYZ SSO", conf.OIDC.IDPName)
3638
}
3739

3840
func TestLocalAuthDisabled(t *testing.T) {

config/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ const (
4242
EnvOIDCLinkByUsername = "GOTIFY_OIDC_LINK_BY_USERNAME"
4343
EnvLocalAuthEnabled = "GOTIFY_LOCALAUTH_ENABLED"
4444
EnvOIDCScopes = "GOTIFY_OIDC_SCOPES"
45+
EnvOIDCIDPName = "GOTIFY_OIDC_IDP_NAME"
4546
EnvNoColor = "NOCOLOR"
4647
)

docs/spec.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2947,7 +2947,8 @@
29472947
"version",
29482948
"register",
29492949
"localAuth",
2950-
"oidc"
2950+
"oidc",
2951+
"oidcIdpName"
29512952
],
29522953
"properties": {
29532954
"localAuth": {
@@ -2962,6 +2963,12 @@
29622963
"x-go-name": "Oidc",
29632964
"example": true
29642965
},
2966+
"oidcIdpName": {
2967+
"description": "Name of the OIDC identity provider.",
2968+
"type": "string",
2969+
"x-go-name": "OIDCIDPName",
2970+
"example": "OIDC"
2971+
},
29652972
"register": {
29662973
"description": "If registration is enabled.",
29672974
"type": "boolean",

gotify-server.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@
228228
# Type: boolean
229229
# GOTIFY_LOCALAUTH_ENABLED=true
230230

231+
# Name of the OIDC identity provider displayed in UI.
232+
# Type: text
233+
# Example: Authelia
234+
# GOTIFY_OIDC_IDP_NAME=OIDC
235+
231236
# Database driver to use. For mysql and postgres the target database must
232237
# already exist and the configured user must have sufficient permissions.
233238
#

model/gotifyinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ type GotifyInfo struct {
2424
// required: true
2525
// example: true
2626
Oidc bool `json:"oidc"`
27+
// Name of the OIDC identity provider.
28+
//
29+
// required: true
30+
// example: OIDC
31+
OIDCIDPName string `json:"oidcIdpName"`
2732
}

router/router.go

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

123-
ui.Register(g, *vInfo, conf.Registration, conf.LocalAuthEnabled, conf.OIDC.Enabled)
123+
ui.Register(g, *vInfo, conf.Registration, conf.LocalAuthEnabled, conf.OIDC.Enabled, conf.OIDC.IDPName)
124124

125125
if conf.OIDC.Enabled {
126126
oidcHandler := api.NewOIDC(conf, db, userChangeNotifier)
@@ -191,7 +191,13 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
191191
// schema:
192192
// $ref: "#/definitions/GotifyInfo"
193193
g.GET("gotifyinfo", func(ctx *gin.Context) {
194-
ctx.JSON(200, &model.GotifyInfo{Version: vInfo.Version, Oidc: conf.OIDC.Enabled, Register: conf.Registration, LocalAuth: conf.LocalAuthEnabled})
194+
ctx.JSON(200, &model.GotifyInfo{
195+
Version: vInfo.Version,
196+
Oidc: conf.OIDC.Enabled,
197+
Register: conf.Registration,
198+
LocalAuth: conf.LocalAuthEnabled,
199+
OIDCIDPName: conf.OIDC.IDPName,
200+
})
195201
})
196202

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

router/router_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func (s *IntegrationSuite) BeforeTest(string, string) {
4242
g, closable := Create(
4343
s.db.GormDatabase,
4444
&model.VersionInfo{Version: "1.0.0", BuildDate: "2018-02-20-17:30:47", Commit: "asdasds"},
45-
&config.Configuration{PassStrength: 5, LocalAuthEnabled: true},
45+
&config.Configuration{
46+
PassStrength: 5,
47+
LocalAuthEnabled: true,
48+
OIDC: config.OIDC{IDPName: "Company XYZ SSO"},
49+
},
4650
)
4751
s.closable = closable
4852
s.server = httptest.NewServer(g)
@@ -60,6 +64,12 @@ func (s *IntegrationSuite) TestVersionInfo() {
6064
doRequestAndExpect(s.T(), req, 200, `{"version":"1.0.0", "commit":"asdasds", "buildDate":"2018-02-20-17:30:47"}`)
6165
}
6266

67+
func (s *IntegrationSuite) TestGotifyInfo() {
68+
req := s.newRequest("GET", "gotifyinfo", "")
69+
70+
doRequestAndExpect(s.T(), req, 200, `{"version":"1.0.0", "oidc":false, "register":false, "localAuth":true, "oidcIdpName":"Company XYZ SSO"}`)
71+
}
72+
6373
func (s *IntegrationSuite) TestHeaderInProd() {
6474
mode.Set(mode.Prod)
6575
req := s.newRequest("GET", "version", "")

ui/serve.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,28 @@ import (
1616
var box embed.FS
1717

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

2526
// Register registers the ui on the root path.
26-
func Register(r *gin.Engine, version model.VersionInfo, register, localAuthEnabled, oidcEnabled bool) {
27+
func Register(
28+
r *gin.Engine,
29+
version model.VersionInfo,
30+
register bool,
31+
localAuthEnabled bool,
32+
oidcEnabled bool,
33+
oidcIDPName string,
34+
) {
2735
uiConfigBytes, err := json.Marshal(uiConfig{
28-
Version: version,
29-
Register: register,
30-
LocalAuth: localAuthEnabled,
31-
OIDC: oidcEnabled,
36+
Version: version,
37+
Register: register,
38+
LocalAuth: localAuthEnabled,
39+
OIDC: oidcEnabled,
40+
OIDCIDPName: oidcIDPName,
3241
})
3342
if err != nil {
3443
panic(err)

ui/src/ElevateStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ElevateStore {
8282
}
8383

8484
if (!this.elevated) {
85-
this.snack('OIDC elevation was not completed.');
85+
this.snack(`${config.get('oidcIdpName')} elevation was not completed.`);
8686
}
8787
this.cleanupOidcElevate();
8888
};

0 commit comments

Comments
 (0)