-
Notifications
You must be signed in to change notification settings - Fork 10
Add OAuth #52
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
Draft
acrosman
wants to merge
30
commits into
main
Choose a base branch
from
feature/add-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add OAuth #52
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6c2c335
Adding new controls
acrosman 87f6e0d
Pass auth mode to main.
acrosman ce64da5
Refactor of login calls.
acrosman 47f80cd
Initial draft of oauth interface (non-functional)
acrosman 09337b4
Removed unused elements
acrosman 8ecc59b
Fixed Login failure message
acrosman c90fb54
correction to partition setup
acrosman fa80e68
Further session correction
acrosman 46b44e4
Revert "Further session correction"
acrosman 25c34bf
partion name change
acrosman 57bc59b
Merge branch 'main' into feature/add-oauth
acrosman ad80c65
Merge branch 'issue-54' into feature/add-oauth
acrosman 95a2e32
minor tweaks
acrosman d434f52
Merge branch 'main' into feature/add-oauth
acrosman b1fc891
Finish Main back merge
acrosman a4f9304
Refactor password login into own function
acrosman 4bcd394
Ensure passwords do not contain whitespace.
acrosman 264060f
Switch to browser instead of local window
acrosman e12abee
Updates to use browser auth not local.
acrosman 69d340d
And URL pattern filtering on open requests for better security.
acrosman 28bb033
Remove extra Electron elements
acrosman ce3262e
Add schema check Login URL checker
acrosman 853153a
Adding oauth test stub.
acrosman f4af7a9
Fix linting error
acrosman 87792ed
Merge branch 'main' into feature/add-oauth
acrosman 2f1922d
Merge branch 'main' into feature/add-oauth
acrosman f573c98
Remove unneeded tests
acrosman 4df801b
Merge branch 'feature/add-oauth' of github.com:acrosman/Salesforce2Sq…
acrosman fa4cd9e
Adding oauth preferences and removing multiple connections
acrosman 8d35f15
Update readme with OAuth instructions
acrosman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| const electron = require("electron"); // eslint-disable-line | ||
|
|
||
| // Extract the needed elements. | ||
| const { | ||
| BrowserWindow, | ||
| session, | ||
| } = electron; | ||
|
|
||
| // Additional Tooling. | ||
| const jsforce = require('jsforce'); | ||
|
|
||
| function createAuthWindow() { | ||
| // Lock down the session. | ||
| const authSession = session.fromPartition('auth-partition'); | ||
| authSession.setPermissionRequestHandler((webContents, permission, callback) => { | ||
| callback(false); | ||
| }); | ||
|
|
||
| // Create the browser window. | ||
| let authWindow = new BrowserWindow({ | ||
| width: 300, | ||
| height: 500, | ||
| resizable: false, | ||
| frame: false, | ||
| show: false, | ||
| session: authSession, | ||
| webPreferences: { | ||
| devTools: true, | ||
| nodeIntegration: false, // Disable nodeIntegration for security. | ||
| nodeIntegrationInWorker: false, | ||
| nodeIntegrationInSubFrames: false, | ||
| disableBlinkFeatures: 'Auxclick', // See: https://github.com/doyensec/electronegativity/wiki/AUXCLICK_JS_CHECK | ||
| contextIsolation: true, // Enabling contextIsolation to protect against prototype pollution. | ||
| worldSafeExecuteJavaScript: true, // https://github.com/electron/electron/pull/24712 | ||
| enableRemoteModule: false, // Turn off remote to avoid temptation. | ||
| // preload: path.join(app.getAppPath(), 'app/authPreload.js'), | ||
| }, | ||
| }); | ||
|
|
||
| // Emitted when the window is closed. | ||
| authWindow.on('closed', () => { | ||
| // Dereference the window object, usually you would store windows | ||
| // in an array if your app supports multi windows, this is the time | ||
| // when you should delete the corresponding element. | ||
| authWindow = null; | ||
| }); | ||
|
|
||
| authWindow.webContents.on('did-fail-load', () => { | ||
| console.log('did-fail-load'); | ||
| }); | ||
|
|
||
| return authWindow; | ||
| } | ||
|
|
||
| function attemptLogin(authDomain) { | ||
| const jsfOauth = new jsforce.OAuth2({ | ||
| loginUrl: authDomain, | ||
| // Temporary testing value from trailhead org. | ||
| clientId: '3MVG9cHH2bfKACZaQ.djia5w9g24IaXl.LCkYPmKS.T7ud235Q8c1pX0_zN6xkDBj.88d1qLf1pTcmZwGODB.', | ||
| redirectUri: 'https://localhost/completesetup', | ||
| }); | ||
|
|
||
| const authWindow = createAuthWindow(); | ||
|
|
||
| // Prepare to filter only the callbacks for my redirectUri | ||
| const filter = { | ||
| urls: [`${authDomain}/*`], | ||
| }; | ||
|
|
||
| // Intercept 302's triggered on page load attempt and redirect. | ||
| authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => { | ||
| const { statusCode, responseHeaders } = details; | ||
|
|
||
| // This is redirect, so let's try again. | ||
| if (statusCode === 302) { | ||
| authWindow.loadURL(responseHeaders.Location.pop()); | ||
| } | ||
|
|
||
| // don't forget to let the request proceed | ||
| callback({ | ||
| cancel: false, | ||
| }); | ||
| }); | ||
|
|
||
| // 'will-navigate' is an event emitted when the window.location changes | ||
| // newUrl should contain the tokens you need | ||
| authWindow.webContents.on('will-navigate', (event, newUrl) => { | ||
| console.log(`Redirected to: ${newUrl}`); | ||
| // More complex code to handle tokens goes here. | ||
| }); | ||
|
|
||
| authWindow.once('ready-to-show', () => { | ||
| authWindow.show(); | ||
| }); | ||
|
|
||
| // Load the authUrl from Salesforce. | ||
| const authUrl = jsfOauth.getAuthorizationUrl({ scope: 'api id web refresh_token' }); | ||
| authWindow.loadURL(authUrl); | ||
| } | ||
|
|
||
| exports.attemptLogin = attemptLogin; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.