Flutter: Google sign in with REST API server in passport nod



我使用护照在我的REST api服务器上设置了Google Sign。它在浏览器中工作得很好,但是当试图将它与flutter客户端集成时,它在响应中返回html正文,这与Google的Oauth Page相同,但是如何通过flutter与它交互?

我不想使用firebase,我想使用我自己的REST api服务器,所以有一种方法可以通过谷歌从我的flutter客户端使用相同的服务器端护照谷歌oauth实现登录?谢谢!

我在服务器端使用以下代码:呼吁护照谷歌战略:

router.get("/auth/google", passport.authenticate("google", {
scope: [
"profile",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/user.gender.read",
"https://www.googleapis.com/auth/user.birthday.read",
],
}));

在护照中设置Google策略:

passport.use(
new GoogleStrategy(
{
// Options for Google Strategy
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
callbackURL: "/auth/google/redirect",
},
(accessToken, refreshToken, profile, done) => {
// Getting the profile info in the profile object here
// Processing and saving to database and returning token here
}));

这段代码在服务器运行时可以很好地与浏览器一起工作。在使用flutter客户端访问时,我使用以下代码:

var client = http.Client();
// Setting host to server url
var host = ServerConfigurations.serverUrl;
// Sending the request to url
var url = Uri.parse(host + '/auth/google');
var response = await client.get(url);
print(response.body)

我在response.body中得到以下输出:

& lt; !doctype html>窗口。WIZ_global_data ={"Mo6CHc" -1837354689584917033,"OewCAd":"% .@ !"xsrf", null,","AFoagUULlmYCAAPS_i54RaA1IYHMtpObpA: 1629146249091")","Qzxixc":"S-15920024:1629146249091588","thykhd":"AKH95etLw808YNsVCgaUcE1PDuZ-9LWIBpdXwNoEGupH-bJFW7ote5ATz8bZB2iQ0DBiB-q7XELpdkCrfXHUe68OcXo091I3LI-CHaQICAFqdeziYoXgFeI u003d","w2btAe":"% .@.null, null,",假,空,空,空,假),},的迹象in - Google帐户(function(H) {H. classname ="CMgTXc"})(document.documentElement);(function(){var z=function(x,O,J,w,S,q,f,u,k,D, x, C, k, b,r,e,P, C, w, P, y){r

对不起,我的英语不好,我认为你可以使用web视图,我认为你可以用webview来显示你的登录,你需要在你的节点服务器上创建这个url然后把它传递给webview在你退出webview的时候你会用其他端点再次检查你的api所以你知道我是否登录,这个端点会返回jwt令牌

最新更新