- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Nodejs 应用服务器尝试访问我的组织 OneDrive 上的文件。该应用程序已在 Azure 中注册,我可以进行图形 api 调用并获取结果。当我尝试调用 onedrive api 时,它挂起而没有响应,api 是:
https://-my.sharepoint.com/personal//_api/file
我使用的资源ID是“https://-my.sharepoint.com”。我也尝试过 Microsoft.Sharepoint
我像这样传递 oauth token (在 header 中):
'Authorization': 'Bearer ' + aToken,
'Accept': 'application/json;odata=minimalmetadata;charset=utf-8'
我还尝试在 Azure 中的资源 ID ( http://office.microsoft.com/sharepoint/ ) 中添加 Office 365 在线共享点的 URL,但这会返回错误资源未为该帐户注册。
<小时/>在 Chrome 请求 header 上使用 REST 工具,如下所示:
接受:application/json授权:持有者 eyJ0eXAiOiJKV1QiLCJhbGci...连接:保持事件状态内容类型:application/xml来源:chrome-extension://rest-console-id用户代理:Mozilla/5.0(Macintosh;Intel Mac OS X 10_9_5)AppleWebKit/537.36(KHTML,如 Gecko)Chrome/38.0.2125.104 Safari/537.36
响应 header :
Status Code: 200
Date: Mon, 20 Oct 2014 18:53:55 GMT
Content-Encoding: gzip
Vary: Accept-Encoding
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Transfer-Encoding: chunked
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
X-SharePointHealthScore: 0
X-SP-SERVERSTATE: ReadOnly=0
request-id: 5611c49c-b0b2-1000-8ca2-5acda39588a3
MicrosoftSharePointTeamServices: 16.0.0.3312
X-MS-InvokeApp: 1; RequireReadOnly
Last-Modified: Mon, 20 Oct 2014 18:53:54 GMT
Server: Microsoft-IIS/7.5
SPRequestGuid: 5611c49c-b0b2-1000-8ca2-5acda39588a3
X-FRAME-OPTIONS: SAMEORIGIN
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Cache-Control: private, max-age=0
SPClientServiceRequestDuration: 1642
X-Content-Type-Options: nosniff
Expires: Sun, 05 Oct 2014 18:53:54 GMT
Request:
Request Url: https://xxxx-my.sharepoint.com/personal/satish_ramjee_xxxxx_co_uk/_api/files
Request Method: GET
Status Code: 200
Params: {}
相关代码如下
'use strict';
var express = require('express');
var request = require('request');
var http = require('http');
var path = require('path');
var passport = require('passport');
var AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2');
var engine = require('ejs-locals');
var app = express();
var config = {
// Enter the App ID URI of your application. To find this value in the Windows Azure Management Portal,
// click Active Directory, click Integrated Apps, click your app, and click Configure.
// The App ID URI is at the bottom of the page in the Single Sign-On section.
realm: 'http://localhost:4000',
// Enter the endpoint to which your app sends sign-on and sign-out requests when using WS-Federation protocol.
// To find this value in the Windows Azure Management Portal, click Active Directory, click Integrated Apps,
// and in the black menu bar at the bottom of the page, click View endpoints.
// Then, copy the value of the WS-Federation Sign-On Endpoint.
// Note: This field is ignored if you specify an identityMetadata url
identityProviderUrl: 'https://login.windows.net/8b87af7d-8647-xxxxxxx/wsfed',
// Enter the logout url of your application. The user will be redirected to this endpoint after
// the auth token has been revoked by the WSFed endpoint.
logoutUrl: 'http:/localhost:4000/',
// Enter the URL of the federation metadata document for your app or the cert of the X.509 certificate found
// in the X509Certificate tag of the RoleDescriptor with xsi:type="fed:SecurityTokenServiceType" in the federation metadata.
// If you enter both fields, the metadata takes precedence
identityMetadata: 'https://login.windows.net/8b87af7d-8647-4dc7-xxxxxxxx/federationmetadata/2007-06/federationmetadata.xml'
};
var graphConfig = {
// Enter the domain for your Active directory subscription, such as contoso.onmicrosoft.com
tenant: '8b87af7d-8647-4dc7-xxxxxxxxxxxxxxx',
// Enter the Client ID GUID of your app.
// In the Windows Azure Management Portal, click Active Directory, click your tenant,
// click Integrated Apps, click your app, and click Configure.
// The Client ID is on this app configuration page.
clientid: '2462ee60-5695-xxxxxxxxxxxxxx',
//Enter the value of the key for the app. You can create the key on the Configure page for the app.
// The value appears only when you first save the key. Enter the saved value.
clientsecret: 'xxxxxxxxxxxxxxxx'
};
// array to hold logged in users
var users = [];
// AAD Graph Client for AAD queries
var graphClient = null;
var aToken;
// use ejs-locals for all ejs templates:
app.engine('ejs', engine);
app.configure(function(){
app.set('port', process.env.PORT || 4000);
app.set('views',__dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session({ secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
var findByEmail = function (email, fn) {
for (var i = 0, len = users.length; i < len; i++) {
var user = users[i];
if (user.email === email) {
return fn(null, user);
}
}
return fn(null, null);
};
// Simple route middleware to ensure user is authenticated.
// Use this route middleware on any resource that needs to be protected. If
// the request is authenticated (typically via a persistent login session),
// the request will proceed. Otherwise, the user will be redirected to the
// login page.
var ensureAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login');
};
//var RESOURCE = "https://graph.windows.net";
//var REST_CALL = 'https://graph.windows.net/' + graphConfig.tenant + '/Users()';
var RESOURCE = "https://xxxx-my.sharepoint.com";
var REST_CALL = "https://xxxx-my.sharepoint.com/personal/satish_ramjee_xxxxxx_co_uk/_api/files";
//passport.use(wsfedStrategy);
passport.use(new AzureAdOAuth2Strategy ({
clientID: graphConfig.clientid,
clientSecret: graphConfig.clientsecret,
tenant: graphConfig.tenant,
resource: RESOURCE,
callbackURL: "http://localhost:4000/callback",
},
function(accessToken, refreshToken, params, profile, done) {
console.log("access token ---> " + accessToken);
aToken = accessToken;
console.log("done ---> " + JSON.stringify(done));
var waadProfile = profile || jwt.decode(params.id_token, '', true);
console.log("waad ---> " + JSON.stringify(waadProfile));
// _res.redirect("/ok");
// User.findOrCreate({ id: waadProfile.upn }, function (err, user) {
return done();
// });
}));
var sp_files = function(callback) {
var headers = {
'Authorization': 'Bearer ' + aToken,
'Accept': 'application/json',
};
if (RESOURCE.indexOf("graph") != -1) {
headers[ 'x-ms-dirapi-data-contract-version'] = '0.5';
}
console.log("CALL___________________ "+REST_CALL);
request({
url: REST_CALL,
// qs: qs,
headers: headers
}, function(err, resp, body) {
console.log("Body " + body);
console.log("Err " + err);
// if (err) return callback(err, null);
if (resp && resp.statusCode != 200) {
return callback(new Error(body), null);
}
else if (!resp) {
return callback(null, null);
}
// { results:
// [ { __metadata: [Object],
// Manager: [Object],
// DirectReports: [Object],
var d = JSON.parse(body).d,
users = d.results;
// meta = buildMetadata(d);
console.log("users" + users);
return callback(users);
})
console.log("Sent request---->");
}
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
var graphQuery = function(res, user) {
graphClient.getUsers(function(err, result) {
if(err) {
res.end('GraphClient.getUsers error:' + err + '\n');
} else {
console.log("User " + JSON.stringify(result) );
//res.render('index', { user: user, data: JSON.stringify(result) });
}
// get user properties (user.DisplayName, user.Mail, etc.)
});
};
var doWaad = function(res, user) {
if(graphClient === null) {
waad.getGraphClientWithClientCredentials2(graphConfig.tenant, graphConfig.clientid, graphConfig.clientsecret, function(err, client) {
if(err) {
res.end('waad.getGraphClientWithClientCredentials2 error:' + err + '\n');
} else {
graphClient = client;
graphQuery(res, user);
}
});
} else {
graphQuery(res, user);
}
};
app.get('/cb', function(req, res) {
console.log("cb");
});
app.get('/fail', function(req, res) {
console.log("fail");
});
app.get('/ok', function(req, res) {
console.log("*************** ok ", req.user);
//doWaad(res, req.user);
});
app.get('/', function(req, res){
if (aToken) {
console.log("T: " + aToken);
sp_files(function(d) {
var mail = [];
if (d)
for (var i=0; i< d.length; i++) {
console.log(i + ">>>> " + d[i]);
// if (d[i].Mail)
// mail.push(d[i].Mail);
if (d[i])
mail.push(JSON.stringify(d[i]));
}
res.render('result', { user: d, data: mail, oauth: aToken});
});
} else {
res.render('index', { user: null});
}
});
app.get('/account', ensureAuthenticated, function(req, res){
res.render('account', { user:req.user });
});
app.get('/login',
passport.authenticate('azure_ad_oauth2', {
failureRedirect: '/fail'
})
);
app.get('/callback',
passport.authenticate('azure_ad_oauth2', { failureRedirect: '/', failureFlash: true }),
function(req, res) {
// Successful authentication, redirect home.
console.log("================= callback");
res.redirect('/ok');
}
);
app.get('/logout', function(req, res){
// clear the passport session cookies
req.logout();
// We need to redirect the user to the WSFED logout endpoint so the
// auth token will be revoked
wsfedStrategy.logout({}, function(err, url) {
if(err) {
res.redirect('/');
} else {
res.redirect(url);
}
});
});
// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing.
passport.serializeUser(function(user, done) {
done(null, user.email);
});
passport.deserializeUser(function(id, done) {
findByEmail(id, function (err, user) {
done(err, user);
});
});
这是主要的 app.js 节点代码,它适用于 graph api,但不适用于 sharepoint api。一旦收到 token ,就会调用函数 sp_files 来发出 https 请求。 sharepoint 调用挂起,没有响应,尽管这是 javascript,但它仍然是服务器端,因此跨域问题不应与此处相关。
最佳答案
好的,问题已经解决了,sharepoint 运行在 IIS 上,不支持 TLS,但支持 SSLv3。 NodeJS 默认使用 TLS,我将其更改为使用 SSLv3,现在可以使用了。
然而,不幸的是,最近发现 SSLv3 很容易受到 POODLE MITM 攻击。
关于javascript - 使用 NodeJS 访问 OneDrive for Business Javascript 无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26297050/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
PowerShell Web Access 允许您通过 Web 浏览器运行 PowerShell cmdlet。它显示了一个基于 Web 的控制台窗口。 有没有办法运行 cmdlet 而无需在控制台窗
我尝试在无需用户登录的情况下访问 Sharepoint 文件。 我可以通过以下任一方式获取访问 token 方法一: var client = new RestClient("https://logi
我目前正在尝试通过 Chrome 扩展程序访问 Google 服务。我的理解是,对于 JS 应用程序,Google 首选的身份验证机制是 OAuth。我的应用目前已成功通过 OAuth 向服务进行身份
假设我有纯抽象类 IHandler 和派生自它的类: class IHandler { public: virtual int process_input(char input) = 0; };
我有一个带有 ThymeLeaf 和 Dojo 的 Spring 应用程序,这给我带来了问题。当我从我的 HTML 文件中引用 CSS 文件时,它们在 Firebug 中显示为中止。但是,当我通过在地
这个问题已经有答案了: JavaScript property access: dot notation vs. brackets? (17 个回答) 已关闭 6 年前。 为什么这不起作用? func
我想将所有流量重定向到 https,只有 robot.txt 应该可以通过 http 访问。 是否可以为 robot.txt 文件创建异常(exception)? 我的 .htaccess 文件: R
我遇到了 LinkedIn OAuth2: "Unable to verify access token" 中描述的相同问题;但是,那里描述的解决方案并不能解决我的问题。 我能够成功请求访问 toke
问题 我有一个暴露给 *:8080 的 Docker 服务容器. 我无法通过 localhost:8080 访问容器. Chrome /curl无限期挂断。 但是如果我使用任何其他本地IP,我就可以访
我正在使用 Google 的 Oauth 2.0 来获取用户的 access_token,但我不知道如何将它与 imaplib 一起使用来访问收件箱。 最佳答案 下面是带有 oauth 2.0 的 I
我正在做 docker 入门指南:https://docs.docker.com/get-started/part3/#recap-and-cheat-sheet-optional docker-co
我正在尝试使用静态 IP 在 AKS 上创建一个 Web 应用程序,自然找到了一个带有 Nginx ingress controller in Azure's documentation 的解决方案。
这是我在名为 foo.js 的文件中的代码。 console.log('module.exports:', module.exports) console.log('module.id:', modu
我试图理解访问键。我读过https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-se
我正在使用 MGTwitterEngine"将 twitter 集成到我的应用程序中。它在 iOS 4.2 上运行良好。当我尝试从任何 iOS 5 设备访问 twitter 时,我遇到了身份验证 to
我试图理解访问键。我读过https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-se
我正在使用以下 API 列出我的 Facebook 好友。 https://graph.facebook.com/me/friends?access_token= ??? 我想知道访问 token 过
401 Unauthorized - Show headers - { "error": { "errors": [ { "domain": "global", "reas
我已经将我的 django 应用程序部署到 heroku 并使用 Amazon s3 存储桶存储静态文件,我发现从 s3 存储桶到 heroku 获取数据没有问题。但是,当我测试查看内容存储位置时,除
我是一名优秀的程序员,十分优秀!