added OAuth2 displayName and pkce options

This commit is contained in:
Gani Georgiev
2023-11-29 20:19:54 +02:00
parent 995733000f
commit b283ee2263
65 changed files with 421 additions and 226 deletions
+10
View File
@@ -620,6 +620,8 @@ type AuthProviderConfig struct {
AuthUrl string `form:"authUrl" json:"authUrl"`
TokenUrl string `form:"tokenUrl" json:"tokenUrl"`
UserApiUrl string `form:"userApiUrl" json:"userApiUrl"`
DisplayName string `form:"displayName" json:"displayName"`
PKCE *bool `form:"pkce" json:"pkce"`
}
// Validate makes `ProviderConfig` validatable by implementing [validation.Validatable] interface.
@@ -659,6 +661,14 @@ func (c AuthProviderConfig) SetupProvider(provider auth.Provider) error {
provider.SetTokenUrl(c.TokenUrl)
}
if c.DisplayName != "" {
provider.SetDisplayName(c.DisplayName)
}
if c.PKCE != nil {
provider.SetPKCE(*c.PKCE)
}
return nil
}
+13
View File
@@ -11,6 +11,7 @@ import (
"github.com/pocketbase/pocketbase/models/settings"
"github.com/pocketbase/pocketbase/tools/auth"
"github.com/pocketbase/pocketbase/tools/mailer"
"github.com/pocketbase/pocketbase/tools/types"
)
func TestSettingsValidate(t *testing.T) {
@@ -941,6 +942,8 @@ func TestAuthProviderConfigValidate(t *testing.T) {
Enabled: true,
ClientId: "test",
ClientSecret: "test",
DisplayName: "test",
PKCE: types.Pointer(true),
AuthUrl: "https://example.com",
TokenUrl: "https://example.com",
UserApiUrl: "https://example.com",
@@ -978,6 +981,8 @@ func TestAuthProviderConfigSetupProvider(t *testing.T) {
AuthUrl: "test_AuthUrl",
UserApiUrl: "test_UserApiUrl",
TokenUrl: "test_TokenUrl",
DisplayName: "test_DisplayName",
PKCE: types.Pointer(true),
}
if err := c2.SetupProvider(provider); err != nil {
t.Error(err)
@@ -1002,4 +1007,12 @@ func TestAuthProviderConfigSetupProvider(t *testing.T) {
if provider.TokenUrl() != c2.TokenUrl {
t.Fatalf("Expected TokenUrl %s, got %s", c2.TokenUrl, provider.TokenUrl())
}
if provider.DisplayName() != c2.DisplayName {
t.Fatalf("Expected DisplayName %s, got %s", c2.DisplayName, provider.DisplayName())
}
if provider.PKCE() != *c2.PKCE {
t.Fatalf("Expected PKCE %v, got %v", *c2.PKCE, provider.PKCE())
}
}