Example #1
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
}
Example #2
0
//等待Sina授权返回结果
func (service *superRpc) WaitAuthResultBySina(req *msg.OAuth2Request, res *msg.OAuth2Response) error {
	if ch, ok := service.auths[req.GetAuthSid()]; ok {
		defer delete(service.auths, req.GetAuthSid())
		data := <-ch
		if data != nil {
			user := service.super.FindBySinaID(data.AuthUID)
			if user != nil {

			} else {
				res.RetCode = proto.Uint32(uint32(msg.OAtuhRetCode_AUTH_OK))
				res.Accid = proto.Uint64(req.GetAccid())
				res.AuthSid = proto.Uint64(req.GetAuthSid())
				res.User = new(msg.OAtuhUserProfile)
				res.User.Accid = proto.Uint64(req.GetAccid())
				res.User.Oauth = proto.String(data.ServiceName)
				res.User.Name = proto.String(data.AuthName)
			}
		} else {
			res.RetCode = proto.Uint32(uint32(msg.OAtuhRetCode_SINA_AUTH_FAILED))
		}
	}
	return nil
}