Пример #1
0
// loginHandler redirects to Facebook OAuth2 authorization page.
func loginHandler(req *web.Request) {
	m := web.NewValues(
		"client_id", appID, // defined in settings.go
		"scope", "read_stream",
		"redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback")
	req.Redirect("https://graph.facebook.com/oauth/authorize?"+m.FormEncodedString(), false)
}
Пример #2
0
// authCallbackHandler handles redirect from Facebook OAuth2 authorization page.
func authCallbackHandler(req *web.Request) {
	code := req.Param.Get("code")
	if code == "" {
		// should display error_reason
		req.Redirect("/", false)
		return
	}
	f, err := getUrlEncodedForm("https://graph.facebook.com/oauth/access_token",
		web.NewValues(
			"client_id", appID, // defined in settings.go
			"client_secret", appSecret, // defined in settings.go
			"redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback",
			"code", code))
	if err != nil {
		req.Error(web.StatusInternalServerError, err)
		return
	}
	token := f.Get("access_token")
	expires := f.Get("expires")
	if expires == "" {
		expires = "3600"
	}
	maxAge, err := strconv.Atoi(expires)
	if err != nil {
		maxAge = 3600
	} else {
		maxAge -= 30 // fudge
	}
	req.Redirect("/", false,
		web.HeaderSetCookie, web.NewCookie("fbtok", token).
			MaxAge(maxAge-30).String())
}
Пример #3
0
// home handles requests to the home page.
func homeHandler(req *web.Request) {
	token, err := accessToken(req)
	if err != nil {
		loggedOutHandler(req)
		return
	}
	feed, err := getJSON("https://graph.facebook.com/me/home", web.NewValues("access_token", token))
	if err != nil {
		req.Error(web.StatusInternalServerError, err,
			web.HeaderSetCookie, web.NewCookie("fbtok", "").Delete().String())
		return
	}
	homeTemplate.respond(req, web.StatusOK, feed)
}
Пример #4
0
	method            string
	url               string
	param             web.Values
	base              string
	clientCredentials Credentials
	credentials       Credentials
	sig               string
}{
	{
		"GeT",
		"hTtp://pHotos.example.net/photos",
		web.NewValues(
			"oauth_consumer_key", "dpf43f3p2l4k3l03",
			"oauth_token", "nnch734d00sl2jdk",
			"oauth_nonce", "kllo9940pd9333jh",
			"oauth_timestamp", "1191242096",
			"oauth_signature_method", "HMAC-SHA1",
			"oauth_version", "1.0",
			"size", "original",
			"file", "vacation.jpg"),
		"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal",
		Credentials{"dpf43f3p2l4k3l03", "kd94hf93k423kf44"},
		Credentials{"kd94hf93k423kf44", "pfkkdhi9sl3r4s00"},
		"tR3+Ty81lMeYAr/Fid0kMTYa/WM="},
	{
		"GET",
		"http://PHOTOS.example.net:8001/Photos",
		web.NewValues(
			"oauth_consumer_key", "dpf43f3++p+#2l4k3l03",
			"oauth_token", "nnch734d(0)0sl2jdk",
			"oauth_nonce", "kllo~9940~pd9333jh",