Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change successRedirectURL #25

Open
justmedev opened this issue Jan 30, 2021 · 5 comments
Open

Change successRedirectURL #25

justmedev opened this issue Jan 30, 2021 · 5 comments

Comments

@justmedev
Copy link

Is there any non-hacky way to change the successRedirectURL to a custom one or just let it close the window?

Something like:
myApiOauth.openAuthWindowAndGetToken(successRedirectURL="https://localhost/?loginresult=done")

@sgeier
Copy link

sgeier commented Aug 14, 2021

Hey, did you find a solution for this? Thanks

@justmedev
Copy link
Author

Nope

@Auclown
Copy link

Auclown commented Sep 2, 2021

I am also dealing with the same issue. After having a look at the src/index.ts file, I have tried it with

defaultElectronGoogleOAuth2Options.successRedirectURL = 'https://localhost:3000';

but it seems it does not work. Has anyone found a solution for this?

@sgeier
Copy link

sgeier commented Sep 2, 2021

You look at the constructor signature:
constructor(clientId: string, clientSecret: string, scopes: string[], options?: Partial<ElectronGoogleOAuth2Options>);

I do it so:

import ElectronGoogleOAuth2 from '@getstation/electron-google-oauth2';
const envVariables = require('../env-variables.json');


const myApiOauth = new ElectronGoogleOAuth2(
	envVariables.GOOGLE_OAUTH_CLIENT_ID,
	envVariables.GOOGLE_OAUTH_CLIENT_SECRET,
	[
		'openid',
		'profile',
		'email',
		'https://www.googleapis.com/auth/documents',
		'https://www.googleapis.com/auth/drive.file',
		'https://www.googleapis.com/auth/spreadsheets.readonly',
	],
	{
		successRedirectURL: envVariables.OAUTH_REDIRECT_URI + '?app=google',
		refocusAfterSuccess: true,
	},
);

I am spinning up my own local webserver to accept the response.

import http from 'http';
import * as Dropbox from './dropbox';

const port = 5000;

export async function runHttpServer(): Promise<void> {
  await http
    .createServer(function (req, res) {
      res.writeHead(200, { 'Content-Type': 'application/json' });

      const url = req.url;

      // Dropbox specific
      const route = '/oauth';
      if (url && url.indexOf(route) !== -1) {
        const urlSearchParams = new URLSearchParams(url.replace(route, ''));
        const params = Object.fromEntries(urlSearchParams.entries());

        if (params.app === 'dropbox') {
          if (params.code) {
            Dropbox.getAccessTokenFromCode(params.code)
              .then(() => {
                res.write('Thanks for authenticating Dropbox. This page can be closed now.');
                res.end();
              })
              .catch((error) => console.log(error));
          }
        }
        if (params.app === 'google') {
          res.write('Thanks for authenticating Google. This page can be closed now.');
          res.end();
        }
      }

      // Google Auth here.
    })
    .listen(port, function () {
      console.log('[Http] Server started at port', port);
    });
}

@afrieirham
Copy link
Contributor

afrieirham commented Oct 6, 2021

Hi everyone, I just want to share that I found a way to change the successRedirectURL.

Just need to pass it like this.

const myApiOauth = new ElectronGoogleOAuth2(
    process.env.GOOGLE_CLIENT_ID,
    process.env.GOOGLE_CLIENT_SECRET,
    [],
    { successRedirectURL: 'https://google.com' },
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants