mawie81 / electron-oauth2 Goto Github PK
View Code? Open in Web Editor NEWA library to handle OAuth2 authentication for your Electron app.
License: MIT License
A library to handle OAuth2 authentication for your Electron app.
License: MIT License
Hi, thank you for this excellent library. It helped me a ton. It's a great reference for how to do OAuth2 in Electron, and it works out of the box without any issues. I have it working very well with jsforce.
I was wondering if you had considered an option that would allow the current BrowserWindow to be used for OAuth2 sign in. Is there a fundamental reason that wouldn't work? A lot of users find the alwaysOnTop option of the new BrowserWindow annoying, especially if they use a password manager to store passwords or need to Cmd-Tab over to Messages to get a 2FA code).
I'd be interested in doing the work to support same-window OAuth2 if you could point me in the right direction. Thanks a lot again for this great library.
Can you make a sample project of this?
Can't get it to work.
How do you catch the callback? There is no localhost server running.
Error: Object has been destroyed`
When I go back from the authorize to the callback.
Attempting to use electron-oauth2 with Azure Active Directory results in an error because the token request to AAD must specify the "resource" (internal terminology) that the token is to be redeemed against. This takes the form of an additional parameter in the token request, but there isn't any way to do this at the moment.
Implementation thoughts:
Since function tokenRequest(data)
at index.js:75 does a queryString.stringify(data)
call before sending its request, everything is in place except for a way to pass extra data into the data object.
The only place I can require('electron-oauth2')
is from src/system/index.js
. When I require the npm in this file I do not get an error. I was able to make authorization work.
However, when it came time to move electron-oauth2
into antother file src/authorization/index.js
, the simple act of requiring the npm throws an error
TypeError: Cannot read property 'BrowserWindow' of undefined
at Object.<anonymous> (node_modules/electron-oauth2/index.js:9:64)
at Object.<anonymous> (src/authorization/index.js:2:22)
at Object.<anonymous> (src/authorization/index.test.js:1:145)
at <anonymous>
This line of code causes the above error in any file that I add it to except src/system/index.js
which is the entry point for my main electron app.
var electronOauth2 = require('electron-oauth2')
I've tried making up new files and adding this this reqiure statement, it always fails. I've tried adding this require statement to the test, same error. But for some reason it will work from the main electron js file only. Adding this line to that file does not throw any errors during testing or during runtime. It doesn't matter if I use it or not, the mere act of requiring it throws the error.
Hello, I am new to Electron. I wanted to know how to continue to another file after authenticating.
Currently after the authentication, the window just closes. Please help.
Thank you in advance!
Hi,
I am getting this error, and I am very lost since a few days:
Uncaught (in promise) TypeError: BrowserWindow is not a constructor(…) Index.js:35
I would appreciate any help.
Why would you authenticate a public client with OAuth?
You have nowhere to hide the client secret so in the end everyone has access to all the data of all the users.
I think this issue might be affecting this package:
electron/electron#4374
I'm using this package with GitHub GHE OAuth. I have values set for client ID, client secret, redirect URL, token URL, and redirect URI. Currently using Electron 1.3.1
I'm using Node v5.9.1, but it throws a syntax error on https://github.com/mawie81/electron-oauth2/blob/master/index.js#L6.
Would it be acceptable to change it to const BrowserWindow = require('electron').BrowserWindow;
In my case I get 'will-navigate' and a 'did-get-redirect-request' which means onCallback
is called a second time. Resolving a promise a second time does not harm, but the window is already close on the first callback and therefore an exception is raised when trying to access it or close it again.
Another minor issue is that opts.additionalTokenRequestData
throws an exception if no options object is passed in.
I will create a pull request.
I tried to authenticate against Azure AD and ran into some errors.
I'm not sure if it was the right way, but I had to add
, resource: config.resource
after line 87 in your index.js, because Azure needed the resource attribute in the request body to request an authorization code.
(See Use the authorization code to request an access token)
This was necessary to use a config like this:
var config = { clientId: '111', clientSecret: 'xxx', authorizationUrl: 'https://login.microsoftonline.com/common/oauth2/authorize?', tokenUrl: 'https://login.microsoftonline.com/common/oauth2/token', useBasicAuthorizationHeader: false, redirectUri: 'http://localhost', resource: 'https://graph.windows.net/' };
Did I miss something, or is this attribute Azure-specific?
There seems to be very little activity & PRs that fix some breaking issues are not being merged.
I have been playing around with this lib and took the code from the example in thee Readme. After adding all of the config, Im still getting a failure after logging in with spotify login window.
The error is
INVALID_CLIENT: Invalid redirect URI
This might somehow be related to #19 , but the result was a bit different for me...
Using OAuth to login in to streamjar, and logging in via oAuth with Mixer there returned the Code from Mixer that was meant for Streamjar because it resolves as soon as there is a code param...
I've got a quick fix that will check if the redirectUri is in the URI, will do a pull request
I'm trying to use the library to process OAuth2 requests for Mixer.com. Mixer allows you to sign in with a Microsoft, Twitter or Discord account. The electron-oauth2 window will authenticate them with password login, however if they click sign in with Microsoft, they are presented with a blank login. I tried setting sandbox: true in the webPreferences of the parameters passed to the constructor, and that allows the child windows to display and authenticate with their respective services, however when I come back to Mixer and allow the oauth connection, it goes to a white screen and doesn't close the window or return the Auth and refresh tokens. Do you know if there's a way to return the credential with sandbox on, or is there another way to let these child windows be displayed without having to resort to sandbox mode?
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.