Login via oauth2 flow (#725)

Reviewed-on: https://gitea.com/gitea/tea/pulls/725
Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:
techknowlogick
2025-03-18 17:01:49 +00:00
committed by techknowlogick
parent e82dd9e08d
commit 62dc1dde95
10 changed files with 710 additions and 158 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/modules/auth"
"code.gitea.io/tea/modules/task"
"github.com/AlecAivazis/survey/v2"
@ -44,12 +45,22 @@ func CreateLogin() error {
return err
}
loginMethod, err := promptSelectV2("Login with: ", []string{"token", "ssh-key/certificate"})
loginMethod, err := promptSelectV2("Login with: ", []string{"token", "ssh-key/certificate", "oauth"})
if err != nil {
return err
}
switch loginMethod {
case "oauth":
promptYN := &survey.Confirm{
Message: "Allow Insecure connections: ",
Default: false,
}
if err = survey.AskOne(promptYN, &insecure); err != nil {
return err
}
return auth.OAuthLoginWithOptions(name, giteaURL, insecure)
default: // token
var hasToken bool
promptYN := &survey.Confirm{
@ -161,7 +172,6 @@ func CreateLogin() error {
if err = survey.AskOne(promptYN, &versionCheck); err != nil {
return err
}
}
return task.CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper)