package middlewares import ( "backend/providers/wechat" "github.com/gofiber/fiber/v3" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error { // if cookie not exists key "openid", then redirect to the wechat auth page token := c.GetReqHeaders()["Authorization"] if len(token) != 0 { return c.Next() } // get current full url url := c.BaseURL() url = "https://qvyun.mp.jdwan.com" log.WithField("module", "middleware.SilentAuth").Debug("url:", url) to, err := f.client.ScopeAuthorizeURL( wechat.ScopeAuthorizeURLWithRedirectURI(url), wechat.ScopeAuthorizeURLWithState("sns_basic_auth"), ) if err != nil { return errors.Wrap(err, "failed to get wechat auth url") } log.WithField("module", "middleware.SilentAuth").Debug("redirectTo: ", to.String()) return c.Redirect().To(to.String()) }