gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package auth
  4. import (
  5. "context"
  6. "net/http"
  7. user_model "code.gitea.io/gitea/models/user"
  8. "code.gitea.io/gitea/modules/reqctx"
  9. "code.gitea.io/gitea/modules/session"
  10. )
  11. type DataStore = reqctx.ContextDataProvider
  12. // SessionStore represents a session store
  13. type SessionStore session.Store
  14. // Method represents an authentication method (plugin) for HTTP requests.
  15. type Method interface {
  16. // Verify tries to verify the authentication data contained in the request.
  17. // If verification succeeds, it returns either an existing user object (with id > 0)
  18. // or a new user object (with id = 0) populated with the information that was found
  19. // in the authentication data (username or email).
  20. // Second argument returns err if verification fails, otherwise
  21. // First return argument returns nil if no matched verification condition
  22. Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
  23. Name() string
  24. }
  25. // PasswordAuthenticator represents a source of authentication
  26. type PasswordAuthenticator interface {
  27. Authenticate(ctx context.Context, user *user_model.User, login, password string) (*user_model.User, error)
  28. }
  29. // SynchronizableSource represents a source that can synchronize users
  30. type SynchronizableSource interface {
  31. Sync(ctx context.Context, updateExisting bool) error
  32. }