provider.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 and LICENSE.gogs file.
  4. package github
  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. fullname, email, website, location, err := p.config.doAuth(login, password)
  21. if err != nil {
  22. if strings.Contains(err.Error(), "401") {
  23. return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
  24. }
  25. return nil, err
  26. }
  27. return &auth.ExternalAccount{
  28. Login: login,
  29. Name: login,
  30. FullName: fullname,
  31. Email: email,
  32. PublicEmail: "",
  33. Location: location,
  34. Website: website,
  35. }, nil
  36. }
  37. func (p *Provider) Config() any {
  38. return p.config
  39. }
  40. func (*Provider) HasTLS() bool {
  41. return true
  42. }
  43. func (*Provider) UseTLS() bool {
  44. return true
  45. }
  46. func (p *Provider) SkipTLSVerify() bool {
  47. return p.config.SkipVerify
  48. }