mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 03:41:01 +00:00
fix gitea "cannot authenticate user. 403 Forbidden" (#221)
Co-authored-by: slt <samuel.lorch@sp-online.de>
This commit is contained in:
parent
16bdc9fe12
commit
b1ff2541b8
1 changed files with 14 additions and 3 deletions
|
@ -139,13 +139,13 @@ func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User,
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
client, err := c.newClientToken("")
|
||||
// Create Client with Basic Auth
|
||||
client, err := c.newClientBasicAuth(username, password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// since api does not return token secret, if drone token exists create new one
|
||||
client.SetBasicAuth(username, password)
|
||||
resp, err := client.DeleteAccessToken("drone")
|
||||
if err != nil && !(resp != nil && resp.StatusCode == 404) {
|
||||
return nil, err
|
||||
|
@ -392,7 +392,7 @@ func (c *client) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
|
|||
return parseHook(r)
|
||||
}
|
||||
|
||||
// helper function to return the Gitea client
|
||||
// helper function to return the Gitea client with Token
|
||||
func (c *client) newClientToken(token string) (*gitea.Client, error) {
|
||||
httpClient := &http.Client{}
|
||||
if c.SkipVerify {
|
||||
|
@ -403,6 +403,17 @@ func (c *client) newClientToken(token string) (*gitea.Client, error) {
|
|||
return gitea.NewClient(c.URL, gitea.SetToken(token), gitea.SetHTTPClient(httpClient))
|
||||
}
|
||||
|
||||
// helper function to return the Gitea client with Basic Auth
|
||||
func (c *client) newClientBasicAuth(username, password string) (*gitea.Client, error) {
|
||||
httpClient := &http.Client{}
|
||||
if c.SkipVerify {
|
||||
httpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
}
|
||||
return gitea.NewClient(c.URL, gitea.SetBasicAuth(username, password), gitea.SetHTTPClient(httpClient))
|
||||
}
|
||||
|
||||
// helper function to return matching hooks.
|
||||
func matchingHooks(hooks []*gitea.Hook, rawurl string) *gitea.Hook {
|
||||
link, err := url.Parse(rawurl)
|
||||
|
|
Loading…
Reference in a new issue