-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
68 lines (54 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//Import dependencies
var electron = require('electron');
//Import electron modules
var BrowserWindow = electron.BrowserWindow || electron.remote.BrowserWindow;
//Auth object
module.exports = function(provider, opt, cb)
{
//Check the provider
if(typeof provider !== 'object'){ return; }
//Check the options
if(typeof opt !== 'object'){ return; }
//Check the callback method
if(typeof cb !== 'function'){ return; }
//Get the authentication url
return provider.authorization_url(opt, function(error, auth_url)
{
//Check the error
if(error){ return cb(error); }
//Initialize the new browser window
var window = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: false } });
//Load the url
window.loadURL(auth_url);
//Display the authentication window
window.show();
//Handle the callback
var handle_callback = function(url)
{
//Parse the redirected url
return provider.authorization_done(opt, url, window, function()
{
//Destroy the window
window.destroy();
//Get the arguments
var args = [].slice.call(arguments);
//Do the callback with the provided arguments
return cb.apply(null, args);
});
};
//Capture the navigate url
window.webContents.on('will-navigate', function(event, navigate_url)
{
//Handle the callback
return handle_callback(navigate_url);
});
//Capture the redirect request
window.webContents.on('did-get-redirect-request', function(event, old_url, new_url)
{
//Handle the callback
return handle_callback(new_url);
});
});
};
//Exports the providers
module.exports.providers = require('./providers/index.js');