MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / New

Function New

pkg/identityserver/identityserver.go:147–249  ·  view source on GitHub ↗

New returns new *IdentityServer.

(c *component.Component, config *Config)

Source from the content-addressed store, hash-verified

145
146// New returns new *IdentityServer.
147func New(c *component.Component, config *Config) (is *IdentityServer, err error) {
148 ctx := tracer.NewContextWithTracer(c.Context(), tracerNamespace)
149
150 is = &IdentityServer{
151 Component: c,
152 ctx: log.NewContextWithField(ctx, "namespace", logNamespace),
153 config: config,
154 telemetryQueue: config.TelemetryQueue,
155 }
156
157 if err := is.setupStore(); err != nil {
158 return nil, err
159 }
160
161 is.config.OAuth.CSRFAuthKey = is.GetBaseConfig(is.Context()).HTTP.Cookie.HashKey
162 is.config.OAuth.UI.FrontendConfig.EnableUserRegistration = is.config.UserRegistration.Enabled
163 if is.config.UserLogin.SessionTTL < 0 {
164 log.FromContext(is.Context()).WithField("session_ttl", is.config.UserLogin.SessionTTL).Warn(
165 "Negative is.user-login.session-ttl; resetting to 0 (sessions never expire)",
166 )
167 is.config.UserLogin.SessionTTL = 0
168 }
169 is.config.OAuth.Login.SessionTTL = is.config.UserLogin.SessionTTL
170 is.oauth, err = oauth.NewServer(c, &oauthAppStore{is.store}, is.config.OAuth, GenerateCSPString)
171 if err != nil {
172 return nil, err
173 }
174
175 is.account, err = account.NewServer(c, &accountAppStore{is.store}, is.config.OAuth, GenerateCSPString)
176 if err != nil {
177 return nil, err
178 }
179
180 c.AddContextFiller(func(ctx context.Context) context.Context {
181 ctx = is.withRequestAccessCache(ctx)
182 ctx = rights.NewContextWithFetcher(ctx, is)
183 ctx = rights.NewContextWithCache(ctx)
184 return ctx
185 })
186
187 // Tasks initialization.
188 if err := is.initializeTelemetryTasks(is.Context()); err != nil {
189 return nil, err
190 }
191
192 for _, hook := range []struct {
193 name string
194 middleware hooks.UnaryHandlerMiddleware
195 }{
196 {rpctracer.TracerHook, rpctracer.UnaryTracerHook(tracerNamespace)},
197 {rpclog.NamespaceHook, rpclog.UnaryNamespaceHook(logNamespace)},
198 {cluster.HookName, c.ClusterAuthUnaryHook()},
199 } {
200 for _, filter := range []string{
201 "/ttn.lorawan.v3.Is",
202 "/ttn.lorawan.v3.EntityAccess",
203 "/ttn.lorawan.v3.ApplicationRegistry",
204 "/ttn.lorawan.v3.ApplicationAccess",

Callers 1

start.goFile · 0.92

Calls 15

NewContextWithTracerFunction · 0.92
NewContextWithFieldFunction · 0.92
FromContextFunction · 0.92
NewServerFunction · 0.92
NewServerFunction · 0.92
NewContextWithFetcherFunction · 0.92
NewContextWithCacheFunction · 0.92
UnaryTracerHookFunction · 0.92
UnaryNamespaceHookFunction · 0.92
setupStoreMethod · 0.80
AddContextFillerMethod · 0.80

Tested by

no test coverage detected