provider.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package pam
  5. import (
  6. "strings"
  7. "gogs.io/gogs/internal/auth"
  8. )
  9. // Provider contains configuration of a PAM authentication provider.
  10. type Provider struct {
  11. config *Config
  12. }
  13. // NewProvider creates a new PAM authentication provider.
  14. func NewProvider(cfg *Config) auth.Provider {
  15. return &Provider{
  16. config: cfg,
  17. }
  18. }
  19. func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount, error) {
  20. err := p.config.doAuth(login, password)
  21. if err != nil {
  22. if strings.Contains(err.Error(), "Authentication failure") {
  23. return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
  24. }
  25. return nil, err
  26. }
  27. return &auth.ExternalAccount{
  28. Login: login,
  29. Name: login,
  30. }, nil
  31. }
  32. func (p *Provider) Config() interface{} {
  33. return p.config
  34. }
  35. func (p *Provider) HasTLS() bool {
  36. return false
  37. }
  38. func (p *Provider) UseTLS() bool {
  39. return false
  40. }
  41. func (p *Provider) SkipTLSVerify() bool {
  42. return false
  43. }