func()

in oauth/oauth.go [123:164]


func (a *Handler) Response(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	c, err := rellenv.FromContext(ctx)
	if err != nil {
		return err
	}
	if r.FormValue("state") != a.state(w, r) {
		return ctxerr.Wrap(ctx, errInvalidState)
	}

	values := url.Values{}
	values.Set("client_id", strconv.FormatUint(a.App.ID(), 10))
	values.Set("client_secret", a.App.Secret())
	values.Set("redirect_uri", redirectURI(c))
	values.Set("code", r.FormValue("code"))

	atURL := &fburl.URL{
		Scheme:    "https",
		SubDomain: fburl.DGraph,
		Env:       rellenv.FbEnv(ctx),
		Path:      "/oauth/access_token",
		Values:    values,
	}

	req, err := http.NewRequest("GET", atURL.String(), nil)
	if err != nil {
		return ctxerr.Wrap(ctx, errOAuthFail)
	}
	res, err := a.HttpTransport.RoundTrip(req)
	if err != nil {
		return ctxerr.Wrap(ctx, err)
	}
	defer res.Body.Close()
	bd, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return ctxerr.Wrap(ctx, err)
	}
	_, err = h.Write(ctx, w, h.Frag{
		&h.Script{Inner: h.Unsafe("window.location.hash = ''")},
		h.String(string(bd)),
	})
	return err
}