Files
upstream-gitea/services/auth/deploy_token.go
upstream-mirror 52ae0c5802
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:41:59 +05:00

48 lines
1.5 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package auth
import (
"net/http"
deploykey_model "gitea.dev/models/deploykey"
user_model "gitea.dev/models/user"
"gitea.dev/modules/log"
)
var _ Method = &DeployToken{}
// DeployToken authenticates a deploy key token given as HTTP basic auth credential.
// Only add it to an auth group where a repo scoped credential makes sense.
type DeployToken struct{}
func (d *DeployToken) Name() string {
return DeployTokenMethodName
}
// Verify returns a user that stands for the deploy key alone. Its permissions come from the key,
// see access_model.getDeployKeyRepoPermission, so the request can never reach another repository
// or exceed the access mode of the key.
func (d *DeployToken) Verify(req *http.Request, _ http.ResponseWriter, store DataStore, _ SessionStore) (*user_model.User, error) {
authToken := parseAuthBasic(req).authToken
if authToken == "" {
return nil, nil //nolint:nilnil // the auth method is not applicable
}
key, err := deploykey_model.VerifyDeployKeyToken(req.Context(), authToken)
if err != nil {
if deploykey_model.IsErrDeployKeyNotExist(err) {
return nil, nil //nolint:nilnil // not a deploy token, let the other methods try
}
return nil, err
}
if err := deploykey_model.UpdateDeployKeyLastUsed(req.Context(), key.ID); err != nil {
log.Error("UpdateDeployKeyUpdated: %v", err)
}
store.GetData()["LoginMethod"] = DeployTokenMethodName
return user_model.NewDeployKeyUserWithKeyID(key.ID), nil
}