mironal / electron-oauth-helper Goto Github PK
View Code? Open in Web Editor NEWEasy to use helper library for OAuth1 and OAuth2.
License: MIT License
Easy to use helper library for OAuth1 and OAuth2.
License: MIT License
Currently I am doing it with the response of mock so I do not know if it really right. 😅
The login is completed and redirection happens but the response is not received. Am I doing something wrong?
`function googleAuth() {
const options = Object.assign({
show: false,
width: 480,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
},
})
let window = new BrowserWindow(options)
window.once("ready-to-show", () => {
window.show()
})
window.once("closed", () => {
window = null
})
const GoogleClientWebApp = {
client_id: GOOGLE_CLIENT_ID,
client_secret: GOOGLE_CLIENT_SECRET,
redirect_uri: GOOGLE_REDIRECT_URI,
authorize_url: "https://accounts.google.com/o/oauth2/v2/auth",
response_type: "token",
scope: "https://www.googleapis.com/auth/userinfo.profile",
}
const config = GoogleClientWebApp;
const provider = new OAuth2Provider(config)
provider.perform(window)
.then(resp => {
console.log("Response", resp)
})
.catch(error => console.error(error))
}`
when I use the vue, the redirect_uri is a http address like this: http://localhost:8080/signin, but when in Electron app, this address not valid because there isn't a http server exist, so which is the substitude for that address?
Hello there. I tried installing @types/electron-oauth-helper to no avail. Do you know if there are any type declarations available elsewhere? My project is Typescript and too far along to re-write in javascript just for logging into Firebase. Thank you
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
$ npm install electron-oauth-helper --save
import OAuth2Provider from "electron-oauth-helper/oauth2"
$ npm run electron:serve
ERROR Failed to compile with 1 errors6:48:48 PM
This dependency was not found:
* electron-oauth-helper/oauth2 in ./src/background.js
To install it, you can run: npm install --save electron-oauth-helper/oauth2
ERROR Build failed with errors.
$ npm install --save electron-oauth-helper/oauth2
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
?
https://github.com/mironal/electron-oauth-helper/blob/master/example/src/main/config.example.js
Isn't there a security concern about using secret information such as client_id
and client_secret
in the client-side code, as shown in the example?
For example, is it possible for this third party to impersonate the same application?
If this concern exists, would it be ideal to build a workflow through the server-side?
I apologize if this is a strange question.
The next version will be rewritten in TypeScript.
Hello sorry for my english ... i have that code in the main.js ->
(i am using electron-vue)
// firebase
const { OAuth2Provider } = require('electron-oauth-helper')
const firebase = require('firebase')
const queryString = require('query-string')
const mapTypeToConfig = require('../../services/config')
firebase.initializeApp(mapTypeToConfig('Firebase'))
const config = mapTypeToConfig('Firebase')
const provider = new OAuth2Provider(config)
provider.perform().then(resp => {
const query = queryString.parse(resp)
const credential = firebase.auth.GoogleAuthProvider.credential(query.access_token)
firebase.auth().signInWithCredential(credential)
.then(user => { console.log(user) }).catch(error => console.error(error))
}).catch(error => console.error(error))
// firebase
and i have the next error -->
home/matias/git/LearniaInteractive/node_modules/electron-oauth-helper/lib/helper.js:49 Uncaught TypeError: BrowserWindow is not a constructor
at createVanillaWindow (/home/matias/git/LearniaInteractive/node_modules/electron-oauth-helper/lib/helper.js:49)
at OAuth2Provider.perform (/home/matias/git/LearniaInteractive/node_modules/electron-oauth-helper/lib/oauth2.js:116)
at eval (main.js?3b76:30)
at Object.<anonymous> (renderer.js:897)
at __webpack_require__ (renderer.js:680)
at fn (renderer.js:90)
at Object.<anonymous> (renderer.js:814)
at __webpack_require__ (renderer.js:680)
at renderer.js:726
at renderer.js:729
whats is wrong? :D Sorry i am not very good in javascript ...
Thanks for the module :)
"electron-oauth-helper": "5.0.0",
In the file:
/lib/oauth2/helper.ts
the code
const authorizeUrl = `${config.authorize_url}?${querystring.stringify(
authorizeParameters,
)}`
does not create a correct OAuth2-Authorize-URL in case the URL stored in config.authorize_url
already has URL parameters.
For example the config.authorize_url
https://example/oauth2/auth?lang=en
would be converted to the OAuth2-Authorize-URL https://example/oauth2/auth?lang=en?client_id=XXXXXX&redirect_uri=YYYYYY&...
which has two question marks and thereby will most likely not work as intended in most OAuth2-Environments.
This problem seems to affect many if not all earlier versions of the OAuth-Helper as well.
Hello, does it work with >= electron 11.2.1 ?
(node:9925) UnhandledPromiseRejectionWarning: TypeError: OAuth2Provider is not a constructor at createWindow (/Users/yb/PhpstormProjects/desktop/electron/main.js:169:22) at switchErpSystem (/Users/yb/PhpstormProjects/desktop/electron/main.js:713:13) at init (/Users/yb/PhpstormProjects/desktop/electron/main.js:317:5) at /Users/yb/PhpstormProjects/desktop/electron/main.js:363:36
Hey so Ive been trying to implement your plugin but I had to hack about to get it to work.
Im using ionic's capacitor to generate electron and using Angular 7 as my framework.
The electron version is:
"electron": "^4.1.4",
"electron-oauth-helper": "^3.0.0",
"firebase": "5.6.0"
Using your docs I tried implementing everything as you have described in the docs and got no response from the new window.
const provider = new OAuth2Provider(mapTypeToConfig('GoogleClientWebApp'));
const options = Object.assign({
show: false,
width: 800,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
},
})
let window = new BrowserWindow(options);
window.once("ready-to-show", () => {
window.show()
})
window.once("closed", () => {
window = null
})
provider.perform(window).then(resp => {
// window.close()
console.log("Got response (◍•ᴗ•◍):", resp)// <-- Never gets to here
}).catch(error => console.error(error))
I had a dig through the code and discovered in redirect.js this line never finished executing
webContents.session.webRequest.onBeforeRedirect({ urls: [redirectURL] },
detail => {
// Never got to here
debug("will redirect", detail.redirectURL)
if (isRedirectURL(detail.redirectURL)) {
resolve(detail.redirectURL)
}
}
)
But by altering the code to use a string instead of an array fixes it. Ive no idea why it just works after. It could be a possible update to electrn under the hood?
webContents.session.webRequest.onBeforeRedirect({ urls: redirectURL },
detail => {
debug("will redirect", detail.redirectURL)
if (isRedirectURL(detail.redirectURL)) {
resolve(detail.redirectURL)
}
}
)
I thought this might be helpful incase anyone comes accross this too
Hey there, I am using electron 2 + electron-vue and I am trying to get the oAuth token from anilist.co by using this project.
After successfully logging into anilist and allowing access, I am getting redirected to my redirect-uri, get no code reported back and get a few errors in my console.
This is my code to access the auth window:
import { OAuth2Provider } from 'electron-oauth-helper';
import config from './config';
const provider = new OAuth2Provider(config.oauth);
ipcMain.on('auth', (event, arg) => {
provider.perform(oAuthWindow)
.then(resp => {
console.log(resp)
})
.catch(error => console.error(error));
});
and my config file:
module.exports = {
oauth: {
client_id: 'ID_HERE',
client_secret: 'SECRET_HERE',
authorize_url: 'https://anilist.co/api/v2/oauth/authorize',
access_token_url: 'https://anilist.co/api/v2/oauth/token',
redirect_uri: 'http://localhost:9080',
response_type: 'code'
}
};
Hi,
I'm trying to use your electron-oauth-helper referring your example.
But OAuth1Provider and OAuth2Provider is always undefined with this code.
const {
OAuth1Provider,
OAuth2Provider
} = require("electron").remote.require("electron-oauth-helper")
Any help?
After generating code, so access token can't be generated. Works in [email protected]
I'm using Firebase and I'm getting this error. How do I fix it?
Code from dist:
var net = electron_1.default.net;
...
var request = net.request(__assign({}, ops, { headers: headers, method: "POST" }));
I have "net" undefined.
electron: v4.2.12
Thank's @mironal for updating dependency
But it throw's error while installing(Tried to install using npm
and yarn
)
I am attempting to add the Google OAuth "prompt" parameter so that a user is asked to choose an account even if there is only one, giving them the option to enter a new account.
I added "prompt" into my config object however the OAuth2Provider appears to just ignore it.
Google Documentation on Additional Parameters:
https://developers.google.com/identity/protocols/OpenIDConnect#authenticationuriparameters
i have use this library for more than a year and I've never had this problem, when i try to log in with my google account the app redirect in a loop to the url where you select your mail.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.