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:
+48
-3
@@ -42,17 +42,62 @@ func (m Model) renderLogin() string {
|
||||
if m.loginNote != "" {
|
||||
b.WriteString(m.styles.Status.Render(" "+m.loginNote) + "\n\n")
|
||||
}
|
||||
b.WriteString(" " + m.styles.Header.Render("Username: ") + m.loginInputs[loginUsername].View() + "\n")
|
||||
b.WriteString(" " + m.styles.Header.Render("Password: ") + m.loginInputs[loginPassword].View() + "\n\n")
|
||||
if m.sso.active {
|
||||
b.WriteString(m.renderSSOWait())
|
||||
return b.String()
|
||||
}
|
||||
if m.offersPasswords() {
|
||||
b.WriteString(" " + m.styles.Header.Render("Username: ") + m.loginInputs[loginUsername].View() + "\n")
|
||||
b.WriteString(" " + m.styles.Header.Render("Password: ") + m.loginInputs[loginPassword].View() + "\n\n")
|
||||
} else {
|
||||
b.WriteString(m.styles.Muted.Render(" This server signs in with "+m.ssoName()+".") + "\n\n")
|
||||
}
|
||||
switch {
|
||||
case m.loggingIn:
|
||||
b.WriteString(m.styles.Muted.Render(" Signing in…") + "\n")
|
||||
case m.loginErr != "":
|
||||
b.WriteString(m.styles.Error.Render(" "+m.loginErr) + "\n")
|
||||
}
|
||||
if m.canSSO() && m.offersPasswords() {
|
||||
b.WriteString("\n" + m.styles.Muted.Render(" or press ctrl+o to sign in with "+m.ssoName()) + "\n")
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// renderSSOWait is the single sign-on screen: the link to open and the code to
|
||||
// check against it, while the client waits for the approval.
|
||||
func (m Model) renderSSOWait() string {
|
||||
var b strings.Builder
|
||||
l := m.sso.login
|
||||
if l == nil {
|
||||
b.WriteString(m.styles.Muted.Render(" Contacting the server…") + "\n")
|
||||
return b.String()
|
||||
}
|
||||
b.WriteString(" " + m.styles.Header.Render("Sign in with "+m.ssoName()) + "\n\n")
|
||||
b.WriteString(" Open this link in a browser, on any device, and approve the sign-in:\n\n")
|
||||
b.WriteString(" " + m.styles.Accent.Render(l.VerificationURL) + "\n\n")
|
||||
b.WriteString(" " + m.styles.Header.Render("Code: ") + m.styles.Bold.Render(l.UserCode) +
|
||||
m.styles.Muted.Render(" it should match the code on that page") + "\n\n")
|
||||
b.WriteString(m.styles.Muted.Render(fmt.Sprintf(" Waiting for approval… good for %d minutes", (l.ExpiresIn+59)/60)) + "\n")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// loginHelp is the sign-in footer, which depends on what the server offers.
|
||||
func (m Model) loginHelp() string {
|
||||
switch {
|
||||
case m.sso.active:
|
||||
return " esc·cancel"
|
||||
case !m.offersPasswords():
|
||||
if m.canSSO() {
|
||||
return " enter·sign in with " + m.ssoName() + " esc·quit"
|
||||
}
|
||||
return " esc·quit"
|
||||
case m.canSSO():
|
||||
return " tab·next field enter·sign in ctrl+o·" + m.ssoName() + " esc·quit"
|
||||
}
|
||||
return " tab·next field enter·sign in esc·quit"
|
||||
}
|
||||
|
||||
// activeTeamLabel names what the lists are narrowed to.
|
||||
func (m Model) activeTeamLabel() string {
|
||||
if t, ok := m.activeTeam(); ok {
|
||||
@@ -187,7 +232,7 @@ func (m Model) renderFooter() string {
|
||||
return withStatus(" tab·next field enter·set password esc·cancel")
|
||||
|
||||
case modeLogin:
|
||||
return "\n" + m.styles.Footer.Render(" tab·next field enter·sign in esc·quit")
|
||||
return "\n" + m.styles.Footer.Render(m.loginHelp())
|
||||
|
||||
default:
|
||||
switch m.activeSection {
|
||||
|
||||
Reference in New Issue
Block a user