Reputation: 31
I have setup Google Sign in on my REST api server using passport. It works fine with a browser but while trying to integrate it with the flutter client, it returns html body in the response which is the same html of Google's Oauth Page, but how to interact with it through flutter?
I don't want to use firebase, I want to use my own REST api server so is there a way to sign in through google from my flutter client using the same server side passport Google oauth implementation? Thanks!
I am using the following code on the server side: Calling the passport google strategy:
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",
],
}));
Setting up Google Strategy in passport:
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
}));
This code works fine with the browser when server is running. While accessing with flutter client, I am using the following code:
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)
I am getting the following output in response.body:
<!doctype html>window.WIZ_global_data = {"Mo6CHc":-1837354689584917033,"OewCAd":"%.@."xsrf",null,[""],"AFoagUULlmYCAAPS_i54RaA1IYHMtpObpA:1629146249091"]","Qzxixc":"S-15920024:1629146249091588","thykhd":"AKH95etLw808YNsVCgaUcE1PDuZ-9LWIBpdXwNoEGupH-bJFW7ote5ATz8bZB2iQ0DBiB-q7XELpdkCrfXHUe68OcXo091I3LI-CHaQICAFqdeziYoXgFeI\u003d","w2btAe":"%[email protected],null,"",false,null,null,null,false]"};Sign in – Google accounts(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
Upvotes: 3
Views: 2124
Reputation: 11
Sorry for my bad English, I think that you can use web view, I think you can use webview to show your login, you would have to create this url in your node server and just pass it to the webview and in flutter when you exit that webview you check your api again with some other endpoint and so you know if I login or no, this endpoint would have to return the jwt token
Upvotes: 1