HandleLogin is the handler for redirecting the user to the authorization endpoint.
(w http.ResponseWriter, r *http.Request)
| 24 | // HandleLogin is the handler for redirecting the user to the authorization |
| 25 | // endpoint. |
| 26 | func (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 | } |