2017-06-16 1 views
0

Ich baue eine react/electron Desktop-Anwendung mit manueller Facebook Login (https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#dialogresponse).So erkennen Sie Umleitung von externen URI von Electron Desktop-Anwendung geöffnet

Mit einem Klick auf eine Schaltfläche, öffne ich mit shell.openExternal Methode der Login-Dialog, aber ich muss diese Umleitung erkennen und dann das Zugriffs-Token aus dem URI lesen. Ich weiß nicht, wie ich das machen soll (rede newbee hier).

Welches sollte der beste Ansatz sein?

Vielen Dank im Voraus.

Antwort

0

Die richtige Antwort ist dieses Tutorial zu folgen: https://competenepal.com/lets-make-a-facebook-login-system-in-electron-that-actually-works/

musste ich nur diesen Teil implementieren:

var options = { 
    client_id: '', 
    scopes: "public_profile", 
    redirect_uri: "https://www.facebook.com/connect/login_success.html" 
}; 
var authWindow = new BrowserWindow({ width: 450, height: 300, show: false, 
    parent: mainWindow, modal: true, webPreferences: {nodeIntegration:false} }); 
var facebookAuthURL = "https://www.facebook.com/v2.8/dialog/oauth?client_id=" + options.client_id + "&redirect_uri=" + options.redirect_uri + "&response_type=token,granted_scopes&scope=" + options.scopes + "&display=popup"; 
authWindow.loadURL(facebookAuthURL); 
authWindow.show(); 
authWindow.webContents.on('did-get-redirect-request', function (event, oldUrl, newUrl) { 
    var raw_code = /access_token=([^&]*)/.exec(newUrl) || null; 
    var access_token = (raw_code && raw_code.length > 1) ? raw_code[1] : null; 
    var error = /\?error=(.+)$/.exec(newUrl); 

    if(access_token) { 
    FB.setAccessToken(access_token); 
    FB.api('/me', { fields: ['id', 'name', 'picture.width(800).height(800)'] }, function (res) { 
     console.log('response is:', res); 
    }); 
    authWindow.close(); 
    } 
}); 
Verwandte Themen