OAuth

/app/lib/auth/providers.go (723 B)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package auth

import (
"github.com/samber/lo"

"{{{ .Package }}}/app/util"
)

type Providers []*Provider

func (p Providers) Get(id string) *Provider {
return lo.FindOrElse(p, nil, func(x *Provider) bool {
return x.ID == id
})
}

func (p Providers) Contains(id string) bool {
return p.Get(id) != nil
}

func (p Providers) IDs() []string {
return lo.Map(p, func(x *Provider, _ int) string {
return x.ID
})
}

func (p Providers) Titles() []string {
return lo.Map(p, func(x *Provider, _ int) string {
return x.Title
})
}

func (s *Service) Providers(logger util.Logger) (Providers, error) {
if s.providers == nil {
err := s.load(logger)
if err != nil {
return nil, err
}
}
return s.providers, nil
}