Exemplo n.º 1
0
func CallbackSina(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	Code = r.FormValue("oauth_verifier")
	c.Infof("[CallbackSina]RequestToken:%v, rTokenSecret: %v, Code: %v", RequestToken, RequestSecret, Code)

	var atoken oauth.AccessToken
	err := ReadToken(&atoken, "sina.json")
	if err != nil {
		ServeError(c, w, err)
		return
	}

	consumer := oauth.NewConsumer(atoken.Token, atoken.Secret, provider)
	var rtoken oauth.RequestToken

	rtoken.Token = RequestToken
	rtoken.Secret = RequestSecret
	if rtoken.Token != "" && rtoken.Secret != "" && Code != "" {
		tok, err := consumer.AuthorizeToken(&rtoken, Code)
		if err != nil {
			ServeError(c, w, err)
		}
		c.Infof("atoken: %v\n", tok)
		AuthToken = tok.Token
		AuthSecret = tok.Secret
		c.Infof("Get AuthToken: %v, AuthSecret: %v\n", AuthToken, AuthSecret)
		http.Redirect(w, r, "/PublicTimeLineSina", http.StatusMovedPermanently)
		return
	}
	http.Redirect(w, r, "/", http.StatusMovedPermanently)
	return
}
Exemplo n.º 2
0
func TokenSina(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	var atoken oauth.AccessToken
	err := ReadToken(&atoken, "sina.json")
	if err != nil {
		ServeError(c, w, err)
		return
	}

	consumer := oauth.NewConsumer(atoken.Token, atoken.Secret, provider)
	atoken.Token = AuthToken
	atoken.Secret = AuthSecret
	if atoken.Token == "" || atoken.Secret == "" {
		c.Infof("Couldn't have auth token")
		var rtoken oauth.RequestToken
		rtoken.Token = RequestToken
		rtoken.Secret = RequestSecret
		if rtoken.Token == "" || rtoken.Secret == "" {
			c.Infof("Getting Request Token")
			rtoken, url, err := consumer.GetRequestTokenAndUrl("http://go.wifihack.net/")
			RequestToken = rtoken.Token
			RequestSecret = rtoken.Secret
			if err != nil {
				ServeError(c, w, err)
				return
			}
			c.Infof("Got rtoken: %v\n", rtoken)
			c.Infof("Visit this URL:", url)
			url = fmt.Sprintf("%s&oauth_callback=%s", url, callback)
			http.Redirect(w, r, url, http.StatusMovedPermanently)
			return
		}
	}
	http.Redirect(w, r, "/PublicTimeLineSina", http.StatusMovedPermanently)
}