Fix adding login without token on private instances (#392)

fixes #365

Co-authored-by: Norwin <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/392
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Norwin <noerw@noreply.gitea.io>
Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
Norwin
2021-08-30 23:19:45 +08:00
committed by Andrew Thornton
parent d6df0a53b5
commit 3fca309f2c
2 changed files with 13 additions and 12 deletions

View File

@ -142,8 +142,9 @@ func AddLogin(login *Login) error {
return saveConfig()
}
// Client returns a client to operate Gitea API
func (l *Login) Client() *gitea.Client {
// Client returns a client to operate Gitea API. You may provide additional modifiers
// for the client like gitea.SetBasicAuth() for customization
func (l *Login) Client(options ...func(*gitea.Client)) *gitea.Client {
httpClient := &http.Client{}
if l.Insecure {
cookieJar, _ := cookiejar.New(nil)
@ -155,10 +156,9 @@ func (l *Login) Client() *gitea.Client {
}}
}
client, err := gitea.NewClient(l.URL,
gitea.SetToken(l.Token),
gitea.SetHTTPClient(httpClient),
)
options = append(options, gitea.SetToken(l.Token), gitea.SetHTTPClient(httpClient))
client, err := gitea.NewClient(l.URL, options...)
if err != nil {
log.Fatal(err)
}