MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / recordAuthMethods

Function recordAuthMethods

apis/record_auth_methods.go:83–179  ·  view source on GitHub ↗
(e *core.RequestEvent)

Source from the content-addressed store, hash-verified

81}
82
83func recordAuthMethods(e *core.RequestEvent) error {
84 collection, err := findAuthCollection(e)
85 if err != nil {
86 return err
87 }
88
89 result := authMethodsResponse{
90 Password: passwordResponse{
91 IdentityFields: make([]string, 0, len(collection.PasswordAuth.IdentityFields)),
92 },
93 OAuth2: oauth2Response{
94 Providers: make([]providerInfo, 0, len(collection.OAuth2.Providers)),
95 },
96 OTP: otpResponse{
97 Enabled: collection.OTP.Enabled,
98 },
99 MFA: mfaResponse{
100 Enabled: collection.MFA.Enabled,
101 },
102 }
103
104 if collection.PasswordAuth.Enabled {
105 result.Password.Enabled = true
106 result.Password.IdentityFields = collection.PasswordAuth.IdentityFields
107 }
108
109 if collection.OTP.Enabled {
110 result.OTP.Duration = collection.OTP.Duration
111 }
112
113 if collection.MFA.Enabled {
114 result.MFA.Duration = collection.MFA.Duration
115 }
116
117 if !collection.OAuth2.Enabled {
118 result.fillLegacyFields()
119
120 return e.JSON(http.StatusOK, result)
121 }
122
123 result.OAuth2.Enabled = true
124
125 for _, config := range collection.OAuth2.Providers {
126 provider, err := config.InitProvider()
127 if err != nil {
128 e.App.Logger().Debug(
129 "Failed to setup OAuth2 provider",
130 slog.String("name", config.Name),
131 slog.String("error", err.Error()),
132 )
133 continue // skip provider
134 }
135
136 info := providerInfo{
137 Name: config.Name,
138 DisplayName: provider.DisplayName(),
139 Logo: provider.Logo(),
140 State: security.RandomString(30),

Callers

nothing calls this directly

Calls 13

fillLegacyFieldsMethod · 0.95
RandomStringFunction · 0.92
S256ChallengeFunction · 0.92
findAuthCollectionFunction · 0.85
JSONMethod · 0.80
InitProviderMethod · 0.80
LoggerMethod · 0.65
ErrorMethod · 0.65
DisplayNameMethod · 0.65
LogoMethod · 0.65
PKCEMethod · 0.65
BuildAuthURLMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…