Files
opencloud/services/webfinger/pkg/relations/openid_discovery_test.go
Ralf Haferkamp 4f1aca6d90 feat(webfinger): use webfinger properties instead new relations
This works the previous commits so that clients can add an addtional
'platform' query parameter to the webfinger request that  can be used
to query the oidc client id and list of scopes that the clients need
to use when connecting to the IDP.

This also removes the non-standard issuer relatation introduced in a
previous commit as we can just introduce new relations in the
http://openid.net name space.

For IDP like Authentik that create a separate issuer url per Client
(Application in Authentik's terms) it is suggested to just configure
as single Client and use that id for all platforms (i.e. setting
'WEBFINGER_ANDROID_OIDC_CLIENT_ID', 'WEBFINGER_DESKTOP_OIDC_CLIENT_ID',
'WEBFINGER_IOS_OIDC_CLIENT_ID' and 'WEBFINGER_WEB_OIDC_CLIENT_ID' to
same value.

Related: #2088
Related: https://github.com/opencloud-eu/desktop/issues/246
2026-02-17 10:41:35 +01:00

54 lines
1.9 KiB
Go

package relations
import (
"context"
"testing"
"github.com/opencloud-eu/opencloud/services/webfinger/pkg/config"
"github.com/opencloud-eu/opencloud/services/webfinger/pkg/webfinger"
)
func TestOpenidDiscovery(t *testing.T) {
clients := map[string]config.OIDCClientConfig{
"web": {
ClientID: "web",
Scopes: []string{"openid", "profile", "email"},
},
"test": {
ClientID: "test",
Scopes: []string{"test"},
},
}
provider := OpenIDDiscovery("http://issuer.url", clients)
jrd := webfinger.JSONResourceDescriptor{}
provider.Add(context.Background(), "", &jrd)
if len(jrd.Links) != 1 {
t.Errorf("provider returned wrong number of links: %v, expected 1", len(jrd.Links))
}
if jrd.Links[0].Href != "http://issuer.url" {
t.Errorf("provider returned wrong issuer link href: %v, expected %v", jrd.Links[0].Href, "http://issuer.url")
}
if jrd.Links[0].Rel != "http://openid.net/specs/connect/1.0/issuer" {
t.Errorf("provider returned wrong openid connect rel: %v, expected %v", jrd.Links[0].Href, OpenIDConnectRel)
}
if len(jrd.Properties) != 0 {
t.Errorf("provider returned properties for empty platform: %v, expected 0", len(jrd.Properties))
}
jrd = webfinger.JSONResourceDescriptor{}
provider.Add(context.Background(), "test", &jrd)
if len(jrd.Properties) != 2 {
t.Errorf("provider returned wrong number of properties for platform test: %v, expected 2", len(jrd.Properties))
}
if jrd.Properties["http://opencloud.eu/ns/oidc/client_id"] != "test" {
t.Errorf("provider returned wrong client_id property: %v, expected %v", jrd.Properties["http://opencloud.eu/ns/oidc/client_id"], "test")
}
if scopes, ok := jrd.Properties["http://opencloud.eu/ns/oidc/scopes"].([]string); !ok || len(scopes) != 1 || scopes[0] != "test" {
t.Errorf("provider returned wrong scopes property: %v, expected %v", jrd.Properties["http://opencloud.eu/ns/oidc/scopes"], []string{"test"})
}
}