/
strategy.go
114 lines (92 loc) · 2.65 KB
/
strategy.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package lookup
import (
"context"
"encoding/json"
"github.com/pkg/errors"
"github.com/ory/kratos/continuity"
"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/hash"
"github.com/ory/kratos/identity"
"github.com/ory/kratos/selfservice/errorx"
"github.com/ory/kratos/selfservice/flow/login"
"github.com/ory/kratos/selfservice/flow/registration"
"github.com/ory/kratos/selfservice/flow/settings"
"github.com/ory/kratos/session"
"github.com/ory/kratos/ui/node"
"github.com/ory/kratos/x"
"github.com/ory/x/decoderx"
)
// var _ login.Strategy = new(Strategy)
var (
_ settings.Strategy = new(Strategy)
_ identity.ActiveCredentialsCounter = new(Strategy)
)
type lookupStrategyDependencies interface {
x.LoggingProvider
x.WriterProvider
x.CSRFTokenGeneratorProvider
x.CSRFProvider
config.Provider
continuity.ManagementProvider
errorx.ManagementProvider
hash.HashProvider
registration.HandlerProvider
registration.HooksProvider
registration.ErrorHandlerProvider
registration.HookExecutorProvider
registration.FlowPersistenceProvider
login.HooksProvider
login.ErrorHandlerProvider
login.HookExecutorProvider
login.FlowPersistenceProvider
login.HandlerProvider
settings.FlowPersistenceProvider
settings.HookExecutorProvider
settings.HooksProvider
settings.ErrorHandlerProvider
identity.PrivilegedPoolProvider
identity.ValidationProvider
session.HandlerProvider
session.ManagementProvider
}
type Strategy struct {
d lookupStrategyDependencies
hd *decoderx.HTTP
}
func NewStrategy(d any) *Strategy {
return &Strategy{
d: d.(lookupStrategyDependencies),
hd: decoderx.NewHTTP(),
}
}
func (s *Strategy) CountActiveFirstFactorCredentials(cc map[identity.CredentialsType]identity.Credentials) (count int, err error) {
return 0, nil
}
func (s *Strategy) CountActiveMultiFactorCredentials(cc map[identity.CredentialsType]identity.Credentials) (count int, err error) {
for _, c := range cc {
if c.Type == s.ID() && len(c.Config) > 0 {
var conf identity.CredentialsLookupConfig
if err = json.Unmarshal(c.Config, &conf); err != nil {
return 0, errors.WithStack(err)
}
if len(conf.RecoveryCodes) > 0 {
count++
}
}
}
return
}
func (s *Strategy) ID() identity.CredentialsType {
return identity.CredentialsTypeLookup
}
func (s *Strategy) NodeGroup() node.UiNodeGroup {
return node.LookupGroup
}
func (s *Strategy) CompletedAuthenticationMethod(ctx context.Context, _ session.AuthenticationMethods) session.AuthenticationMethod {
return session.AuthenticationMethod{
Method: s.ID(),
AAL: identity.AuthenticatorAssuranceLevel2,
}
}