func()

in oauth/oauth.go [81:121]


func (a *Handler) Start(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	c, err := rellenv.FromContext(ctx)
	if err != nil {
		return err
	}
	values := url.Values{}
	values.Set("client_id", strconv.FormatUint(rellenv.FbApp(ctx).ID(), 10))
	if scope := r.FormValue("scope"); scope != "" {
		values.Set("scope", scope)
	}

	if assetScope := r.FormValue("asset-scope"); assetScope != "" {
		values.Set("asset-scope", assetScope)
	}

	if c.ViewMode == rellenv.Website {
		values.Set("redirect_uri", redirectURI(c))
		values.Set("state", a.state(w, r))
	} else {
		values.Set("redirect_uri", c.ViewURL("/auth/session"))
	}

	dialogURL := fburl.URL{
		Scheme:    "https",
		SubDomain: fburl.DWww,
		Env:       rellenv.FbEnv(ctx),
		Path:      "/dialog/oauth",
		Values:    values,
	}

	if c.ViewMode == rellenv.Website {
		http.Redirect(w, r, dialogURL.String(), 302)
	} else {
		b, _ := json.Marshal(dialogURL.String())
		_, err := h.Write(ctx, w, &h.Script{
			Inner: h.Unsafe(fmt.Sprintf("top.location=%s", b)),
		})
		return err
	}
	return nil
}