0

I am working with VUE 2 and electron with an Asp.net Core Web API backend Backend.

Currently I am working to integrate some functionality with google drive the first hurdle that I am running into is getting the authorization tokens for my app. I have tried several methods that have not panned out. Mostly due to the fact that I am developing with electron.

So what I am attempting right now is using the google NodeJs library I have it to a point where I am getting a successful login within a child window and returning a code that is appended to my redirect URL the redirect URL is set to my kestrel web server http://localhost:5000. With that I am getting a 404 error because if does not match my backend.

This is the format of the code that I am getting

http://localhost:5000/odata/GoogleRequest?code="code line here"

So with that I am at a loss on how to consume the code that is given in a way to get the auth token and refresh token for the application.

this is the code that I have so far

const oauth2Client = new google.auth.OAuth2(
    CLIENT_ID,
    CLIENT_SECRET,
    REDIRECT_URI
);
const authorizationUrl = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES
});

async function getToken(code){
    const { tokens } = await oauth2Client.getToken(code)
    oauth2Client.setCredentials(tokens);
    console.warn(tokens);
}

And the child window code for electron

function createGoogleWindow(){
    let googleWindow = new BrowserWindow({
        parent: win,
        width: 400,
        height: 600,
        webPreferences: {
            webSecurity: false,
            nodeIntegration: true,
            enableRemoteModule: true,
            contextIsolation: false
        }
    });
    if (isDevelopment) googleWindow.webContents.openDevTools();
    googleWindow.menuBarVisible = false;
    googleWindow.on('closed', () => {
        googleWindow = null;
    });
    googleWindow.loadURL(authorizationUrl);
    getToken().catch((error) => {
        console.error(error);
    });
    console.warn('this is the redirect uri', REDIRECT_URI);
    return googleWindow;
}

ipc.on('googleAuth', () => {
    createGoogleWindow();
});

As I am still new to all this I am doing the best I can but at this point I am a little lost on where I should be looking next to get this working ?

If anyone has any Ideas on what I should do please share them.

DRW
  • 335
  • 1
  • 3
  • 17
  • [Does this link useful to you ?](https://dvoituron.com/2019/08/09/webapi-google-auth/) – Jason Pan Jul 20 '22 at 06:55
  • I have tried this method being an installed application I am unable to set the redirect URL in the google console. I have seen information on using a loopback URL but was unsuccessful in setting it up for my application needs. I have to open the login window in a child window in electron. So still working that out. That is why I went with the nodejs api – DRW Jul 20 '22 at 14:13

0 Answers0