Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
48 lines
1.5 KiB
Go
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 "gotea.dev/models/deploykey"
|
|
user_model "gotea.dev/models/user"
|
|
"gotea.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
|
|
}
|