Ich benutze die official Dropbox API (V2) auf meiner Nodejs App. Es klingt wie eine dumme Frage, aber ich wirklich kann nicht herausfinden, wie man das gegebene Zugangstoken von der Rückrufurl erhält. Eigentlich ist es angeblich in die Raute (#) Teil der URL sein (gemäß ihre Dokumentation und javascript client-side exemple), die von der Server-Seite nicht sichtbar ist ...Dropbox api V2, bekomme Zugriffstoken in Abfrageparam statt URL-Hash (#) (Nodejs)
Ich kann keine exemple finden Zur Authentifizierung von einer Nodejs-App, die nur die Basis-API verwendet.
Hier ist meine Authentifizierungscode:
Meine express App:
//Entry point, DC is a DropboxConnector object
app.get('/connect/Dropbox', function(req, res) {
console.log('/connect/Dropbox called');
res.redirect(DC.getConnexionURL());
});
// Callback from the authentication
app.get('/authDropbox', function(req, res) {
console.log("/authDropbox called");
console.log(url.format(req.protocol + '://' + req.get('host') + req.originalUrl));
// The above log is: 'http://localhost:8080/authDropbox'
// Here is the problem, the access token is unreachable by express
DC.getToken(req.query.code, res);
connectorList.push(DC);
});
DropboxConnector.js, meine Dropbox api Wrapper:
var REDIRECT_URI = 'http://localhost:8080/authDropbox';
//The authentication url given by the dropbox api
getConnexionURL() {
dbx = new Dropbox({ clientId: CLIENT_ID});
var authUrl = dbx.getAuthenticationUrl(REDIRECT_URI);
console.log("AuthURL: " + authUrl);
return authUrl;
}
// @param code is supposed to be the access token...
getToken(code, res) {
if (!!code) {
dbx = new Dropbox({ accessToken: code });
console.log("Authenticated!");
res.redirect(CALLBACK_URL);
} else {
console.log("No code here");
}
}
Dank für die Hilfe!
Dank für Ihre große Antwort! Ich werde auf diesen Thread achten, ich werde die hier angebotene Lösung ausprobieren (https://www.npmjs.com/package/dropbox-client-oauth2) oder ich werde die http-API direkt anstelle der Javascript-Version verwenden es hat ganz gut geklappt. – Kapcash
Das SDK unterstützt jetzt den Code-Fluss. Weitere Informationen [hier] (https://github.com/dropbox/dropbox-sdk-js/issues/64#issuecomment-359910107). – Greg
Ich wurde von der GitHub-Ausgabe auch benachrichtigt, aber danke für das Update! – Kapcash