Implement SSO default_provider.

This commit is contained in:
Tommie Gannert 2022-10-04 12:13:42 +02:00
parent b8ac83f8d5
commit 7ceb276970
2 changed files with 35 additions and 1 deletions

View file

@ -70,6 +70,13 @@ func SSORedirect(
}
}
if idpID == "" {
idpID = cfg.DefaultProviderID
if idpID == "" && len(cfg.Providers) > 0 {
idpID = cfg.Providers[0].ID
}
}
callbackURL, err := buildCallbackURLFromOther(cfg, req, "/login/sso/redirect")
if err != nil {
util.GetLogger(ctx).WithError(err).Error("Failed to build callback URL")

View file

@ -37,7 +37,30 @@ func TestSSORedirect(t *testing.T) {
}.Encode(),
},
},
WantLocationRE: `http://auth.example.com/authorize\?callbackURL=http%3A%2F%2Fmatrix.example.com%2F_matrix%2Fv4%2Flogin%2Fsso%2Fcallback%3Fprovider%3D&nonce=.+&providerID=`,
Config: config.SSO{
DefaultProviderID: "adefault",
},
WantLocationRE: `http://auth.example.com/authorize\?callbackURL=http%3A%2F%2Fmatrix.example.com%2F_matrix%2Fv4%2Flogin%2Fsso%2Fcallback%3Fprovider%3Dadefault&nonce=.+&providerID=adefault`,
WantSetCookieRE: "sso_nonce=[^;].*Path=/_matrix/v4/login/sso",
},
{
Name: "redirectFirstProvider",
Req: http.Request{
Host: "matrix.example.com",
URL: &url.URL{
Path: "/_matrix/v4/login/sso/redirect",
RawQuery: url.Values{
"redirectUrl": []string{"http://example.com/continue"},
}.Encode(),
},
},
Config: config.SSO{
Providers: []config.IdentityProvider{
{ID: "firstprovider"},
{ID: "secondprovider"},
},
},
WantLocationRE: `http://auth.example.com/authorize\?callbackURL=http%3A%2F%2Fmatrix.example.com%2F_matrix%2Fv4%2Flogin%2Fsso%2Fcallback%3Fprovider%3Dfirstprovider&nonce=.+&providerID=firstprovider`,
WantSetCookieRE: "sso_nonce=[^;].*Path=/_matrix/v4/login/sso",
},
{
@ -468,6 +491,10 @@ type fakeSSOAuthenticator struct {
}
func (auth *fakeSSOAuthenticator) AuthorizationURL(ctx context.Context, providerID, callbackURL, nonce string) (string, error) {
if providerID == "" {
return "", errors.New("empty providerID")
}
return (&url.URL{
Scheme: "http",
Host: "auth.example.com",