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

Method HandleLogin

pkg/web/oauthclient/login.go:26–51  ·  view source on GitHub ↗

HandleLogin is the handler for redirecting the user to the authorization endpoint.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

24// HandleLogin is the handler for redirecting the user to the authorization
25// endpoint.
26func (oc *OAuthClient) HandleLogin(w http.ResponseWriter, r *http.Request) {
27 next := r.URL.Query().Get(oc.nextKey)
28 // Only allow relative paths.
29 if !strings.HasPrefix(next, "/") && !strings.HasPrefix(next, "#") && !strings.HasPrefix(next, "?") {
30 next = ""
31 }
32
33 // Set state cookie.
34 state := newState(next)
35 if err := oc.setStateCookie(w, r, state); err != nil {
36 webhandlers.Error(w, r, err)
37 return
38 }
39
40 conf, err := oc.oauthConfig(r.Context())
41 if err != nil {
42 webhandlers.Error(w, r, err)
43 return
44 }
45 opts, err := oc.authCodeURLOpts(r.Context())
46 if err != nil {
47 webhandlers.Error(w, r, err)
48 return
49 }
50 http.Redirect(w, r, conf.AuthCodeURL(state.Secret, opts...), http.StatusFound)
51}

Callers

nothing calls this directly

Calls 6

setStateCookieMethod · 0.95
ErrorFunction · 0.92
newStateFunction · 0.85
GetMethod · 0.65
ContextMethod · 0.65
HasPrefixMethod · 0.45

Tested by

no test coverage detected