
var clientId = '220bxxxx-xxxxx-xxxx-xxxx-xxxxxxxxe2b3'; // App Id - GUID var clientSecret = '1Cyf ... 7P6c=' // Client Secret var authorityHostUrl = 'https://login.windows.net'; var tenant = 'foo.onmicrosoft.com'; // Office 365 Tenant var authorityUrl = authorityHostUrl + '/' + tenant; var redirectUri = 'http://localhost:3000/getAToken'; // Callback URL var resource = 'https://foo.sharepoint.com'; // Resource welche von der App genutzt wird var templateAuthzUrl = 'https://login.windows.net/' + tenant + '/oauth2/authorize?response_type=code&client_id=' + clientId + '&redirect_uri=' + redirectUri + '&state=<state>&resource=' + resource;
var loginWindow;
viewModel.authenticate = function() {
loginWindow = window.open("http://localhost:3000/auth");
};
server.get('/auth', function (req, res) {
var token = "foo-token";
res.cookie('authstate', token);
var authorizationUrl = createAuthorizationUrl(token);
res.redirect(authorizationUrl);
});
server.get('/getAToken', function (req, res) {
if (req.cookies.authstate !== req.query.state) {
res.send('error: state does not match');
}
authenticationContext.acquireTokenWithAuthorizationCode(
req.query.code,
redirectUri,
resource,
clientId,
clientSecret,
function (err, response) {
var message = '';
if (err) {
message = 'error: ' + err.message + '\n';
res.status(400).send(message);
} else {
tokenResponse = response;
res.status(200).send("Logged in");
}
}
);
});
ajax({
url: "https:/foo.sharepoint.com/_api/web/lists",
"method": "GET",
"contentType": "application/json;odata=verbose",
"headers": {
"Accept": "application/json;odata=verbose",
"Authorization": "Bearer " + tokenResponse.accessToken,
'Access-Control-Allow-Origin': '*'
},
"crossDomain": true,
"async": true,
"cache": false,
"processData": false
}).success(function (data) {
console.log(JSON.stringify(data));
event.returnValue = JSON.stringify(data);
}).error(function (data) {
console.log(JSON.stringify(data));
event.returnValue = JSON.stringify(data);
});
Kategorien: Cloud, Office 365, Technical
Schlagwörter: ADAL, Authentication, Cloud, Electron, JavaScript, Node.JS, OAuth2, Office365

Haben Sie Fragen zu diesem Artikel oder brauchen Sie Unterstützung?
Nehmen Sie mit uns Kontakt auf!
Wir unterstützen Sie gerne bei Ihren Vorhaben!