Sign in through the server's single sign-on, with a code
The sign-in screen asks the server how it can be signed in to (GET /api/auth/config) and offers what it finds: the password form, and "Sign in with <provider>" when the server can do a device login. The TUI shows a link and a short code, the person approves it in any browser, and the next poll hands over the ordinary session, so it works over SSH where no browser can be opened. The terminal never talks to the identity provider. The password form is hidden when the server has turned password login off. `auth: sso` in config.yaml starts the SSO login straight away, but not right after signing out, where that would sign the person straight back in; any other value is refused when the config is read. Polling honours the server's interval, backs off on slow_down, and gives up after repeated failures rather than retrying forever. A server without /api/auth/config answers 404 and is treated as passwords only, so the sign-in screen is the one it had. Needs terdut-server v0.29.0 for SSO.
This commit is contained in:
@@ -59,3 +59,26 @@ func TestLoad_NoAPIKeyNeeded(t *testing.T) {
|
||||
t.Error("expected the leftover api_key to be noted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_AuthIsOptionalAndChecked(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
yaml, want string
|
||||
bad bool
|
||||
}{
|
||||
{"", "", false},
|
||||
{"auth: password\n", "password", false},
|
||||
{"auth: sso\n", "sso", false},
|
||||
{"auth: oidc\n", "", true},
|
||||
} {
|
||||
writeConfig(t, "server_url: https://terdut.example.com\n"+tc.yaml)
|
||||
cfg, err := Load()
|
||||
switch {
|
||||
case tc.bad && err == nil:
|
||||
t.Errorf("%q: expected an error", tc.yaml)
|
||||
case !tc.bad && err != nil:
|
||||
t.Errorf("%q: %v", tc.yaml, err)
|
||||
case !tc.bad && cfg.Auth != tc.want:
|
||||
t.Errorf("%q: auth %q, want %q", tc.yaml, cfg.Auth, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user