MCPcopy
hub / github.com/writefreely/writefreely / viewOauthInit

Method viewOauthInit

oauth.go:133–164  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

131}
132
133func (h oauthHandler) viewOauthInit(app *App, w http.ResponseWriter, r *http.Request) error {
134 ctx := r.Context()
135
136 var attachUser int64
137 if attach := r.URL.Query().Get("attach"); attach == "t" {
138 user, _ := getUserAndSession(app, r)
139 if user == nil {
140 return impart.HTTPError{http.StatusInternalServerError, "cannot attach auth to user: user not found in session"}
141 }
142 attachUser = user.ID
143 }
144
145 state, err := h.DB.GenerateOAuthState(ctx, h.oauthClient.GetProvider(), h.oauthClient.GetClientID(), attachUser, r.FormValue("invite_code"))
146 if err != nil {
147 log.Error("viewOauthInit error: %s", err)
148 return impart.HTTPError{http.StatusInternalServerError, "could not prepare oauth redirect url"}
149 }
150
151 if h.callbackProxy != nil {
152 if err := h.callbackProxy.register(ctx, state); err != nil {
153 log.Error("viewOauthInit error: %s", err)
154 return impart.HTTPError{http.StatusInternalServerError, "could not register state server"}
155 }
156 }
157
158 location, err := h.oauthClient.buildLoginURL(state)
159 if err != nil {
160 log.Error("viewOauthInit error: %s", err)
161 return impart.HTTPError{http.StatusInternalServerError, "could not prepare oauth redirect url"}
162 }
163 return impart.HTTPError{http.StatusTemporaryRedirect, location}
164}
165
166func configureSlackOauth(parentHandler *Handler, r *mux.Router, app *App) {
167 if app.Config().SlackOauth.ClientID != "" {

Callers 1

TestViewOauthInitFunction · 0.95

Calls 6

getUserAndSessionFunction · 0.85
registerMethod · 0.80
GenerateOAuthStateMethod · 0.65
GetProviderMethod · 0.65
GetClientIDMethod · 0.65
buildLoginURLMethod · 0.65

Tested by 1

TestViewOauthInitFunction · 0.76