Esempio n. 1
0
func handleAuthorize(w http.ResponseWriter, r *http.Request) {
	log.Trace("\n--")
	log.Trace("Visit: " + r.RequestURI)
	//Get the Google URL which shows the Authentication page to the user
	url, _ := auth.SinaOAuth2(123456, func(data *auth.AuthUserData, accid uint64, err error) {
		if data != nil && err == nil {
			log.Trace("获得授权 %d", accid)
			log.Trace("%v", data)
			http.Redirect(data.Response, data.Request, "http://www.tuntun.site/", http.StatusFound)
		} else {
			log.Trace(err.Error())
		}
	})
	log.Trace("URL: %v\n", url)
	//redirect user to that page
	http.Redirect(w, r, url, http.StatusFound)
}
Esempio n. 2
0
//获取SIna授权URL
func (service *superRpc) GetAuthUrlBySina(req *msg.OAuth2Request, res *msg.OAuth2Url) error {
	auth_sid := utils.GenEasyNextId(utils.SnowflakeSystemWork, utils.SnowflakeCatalogAuth)
	auth_ch := make(chan *auth.AuthUserData)
	service.auths[auth_sid] = auth_ch
	url, _ := auth.SinaOAuth2(auth_sid, func(data *auth.AuthUserData, accid uint64, err error) {
		if data != nil && err == nil {
			log.Trace("获得授权 auth_sid:%d data:%v", auth_sid, data)
			auth_ch <- data
		} else {
			log.Trace(err.Error())
			auth_ch <- nil
		}
	})
	res.Accid = proto.Uint64(req.GetAccid())
	res.AuthSid = proto.Uint64(auth_sid)
	res.Url = proto.String(url)
	return nil
}