added option to retrieve the OIDC user info from the id_token payload
This commit is contained in:
@@ -461,13 +461,14 @@ type OAuth2ProviderConfig struct {
|
||||
// (https://github.com/pocketbase/pocketbase/discussions/3799#discussioncomment-7640312)
|
||||
PKCE *bool `form:"pkce" json:"pkce"`
|
||||
|
||||
Name string `form:"name" json:"name"`
|
||||
ClientId string `form:"clientId" json:"clientId"`
|
||||
ClientSecret string `form:"clientSecret" json:"clientSecret,omitempty"`
|
||||
AuthURL string `form:"authURL" json:"authURL"`
|
||||
TokenURL string `form:"tokenURL" json:"tokenURL"`
|
||||
UserInfoURL string `form:"userInfoURL" json:"userInfoURL"`
|
||||
DisplayName string `form:"displayName" json:"displayName"`
|
||||
Name string `form:"name" json:"name"`
|
||||
ClientId string `form:"clientId" json:"clientId"`
|
||||
ClientSecret string `form:"clientSecret" json:"clientSecret,omitempty"`
|
||||
AuthURL string `form:"authURL" json:"authURL"`
|
||||
TokenURL string `form:"tokenURL" json:"tokenURL"`
|
||||
UserInfoURL string `form:"userInfoURL" json:"userInfoURL"`
|
||||
DisplayName string `form:"displayName" json:"displayName"`
|
||||
Extra map[string]any `form:"extra" json:"extra"`
|
||||
}
|
||||
|
||||
// Validate makes OAuth2ProviderConfig validatable by implementing [validation.Validatable] interface.
|
||||
@@ -531,5 +532,9 @@ func (c OAuth2ProviderConfig) InitProvider() (auth.Provider, error) {
|
||||
provider.SetPKCE(*c.PKCE)
|
||||
}
|
||||
|
||||
if c.Extra != nil {
|
||||
provider.SetExtra(c.Extra)
|
||||
}
|
||||
|
||||
return provider, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package core_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -942,6 +944,7 @@ func TestOAuth2ProviderConfigInitProvider(t *testing.T) {
|
||||
UserInfoURL: "test_UserInfoURL",
|
||||
DisplayName: "test_DisplayName",
|
||||
PKCE: types.Pointer(true),
|
||||
Extra: map[string]any{"a": 1},
|
||||
},
|
||||
core.OAuth2ProviderConfig{
|
||||
Name: "gitlab",
|
||||
@@ -952,6 +955,7 @@ func TestOAuth2ProviderConfigInitProvider(t *testing.T) {
|
||||
UserInfoURL: "test_UserInfoURL",
|
||||
DisplayName: "test_DisplayName",
|
||||
PKCE: types.Pointer(true),
|
||||
Extra: map[string]any{"a": 1},
|
||||
},
|
||||
false,
|
||||
},
|
||||
@@ -1011,6 +1015,12 @@ func TestOAuth2ProviderConfigInitProvider(t *testing.T) {
|
||||
if provider.PKCE() != *s.expectedConfig.PKCE {
|
||||
t.Fatalf("Expected PKCE %v, got %v", *s.expectedConfig.PKCE, provider.PKCE())
|
||||
}
|
||||
|
||||
rawMeta, _ := json.Marshal(provider.Extra())
|
||||
expectedMeta, _ := json.Marshal(s.expectedConfig.Extra)
|
||||
if !bytes.Equal(rawMeta, expectedMeta) {
|
||||
t.Fatalf("Expected PKCE %v, got %v", *s.expectedConfig.PKCE, provider.PKCE())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user