gpt4 book ai didi

node.js - UCWA Lync 身份验证 - 500 Web 票证无效

转载 作者:太空宇宙 更新时间:2023-11-03 22:00:13 25 4
gpt4 key购买 nike

我正在尝试使用 Nodejs 创建一个简单的 Lync 客户端。基于http://ucwa.lync.com/documentation/KeyTasks-CreateApplication我做了这样的事情。它一直有效到最后一步#9,此时我应该向 UCWA 注册我的应用程序。服务器响应代码 500 和愚蠢的解释

There is a problem with the resource you are looking for, and it cannot be displayed

和标题

x-ms-diagnostics': '28032;source="mysource";reason="The web ticket is invalid."'

var http = require('request-promise');
var lync = {};

lync.setup = function(email, password){
var self = this;
var hostname = email.split('@');
this.username = email;

//discover urls
return http.get('http://lyncdiscover.'+hostname[1])
.then(function(d) {
var parsed = JSON.parse(d);
self.urls = {
self: parsed._links.self.href,
user: parsed._links.user.href,
xframe: parsed._links.xframe.href
};
return http.get(self.urls.user);
}).catch(function(err){
if(err.statusCode == 401){
var toParse = err.response.headers['www-authenticate'];
var Oauth = toParse.match(/https:\/\/[\d\w\./_-]*/i)[0];

var loginPost = {
grant_type: 'password',
username: email,
password: password
};

return http.post(Oauth, {form:loginPost});
}
return false
}).then(function(data){
var parsed = JSON.parse(data);
//setup authorization
http = http.defaults({
headers: {Authorization: parsed.token_type + ' ' + parsed.access_token}
});
//console.log(self.urls.user);
//console.log('Authorization:'+ parsed.token_type + ' ' + parsed.access_token);
return http.get(self.urls.user);

}).then(function(data){
var parsed = JSON.parse(data);
self.urls.applications = parsed._links.applications.href;

var registerApp = {
culture : "en-us",
endpointId : "2d9dc28d-4673-4035-825c-feb64be28e4e",
userAgent : "Test"
};
var r = "{'userAgent': 'NodeJs', 'endpointId' : '2d9dc28d-4673-4035-825c-feb64be28e4e', 'culture': 'en-US'}";
return http.post(self.urls.applications, {body: registerApp, json:true});
})
.then(function(data){
console.log(data);
})
.catch(function(err){

console.log(err);
return false;
});
};



//run app
lync.setup('login@domain.com', 'password').then(function(ret){

});

这里有一个关键点。这不是我的服务器。我在那里只有一个帐户,可以使用官方 Lync 客户端或 Pidgin 插件登录。是否需要一些额外的步骤来“允许”我的应用程序与 UCWA 配合使用?

@ShelbyZ我可以使用 Oauth 轻松授权。我收到了授权 token ,因此我已登录。

我收到的 json 类似于

"_links":{ "self":{"href":"link"}, "applications":{"href":"i need this"}, "xframe":{"href":"link"} } }

现在。我需要“注册我的应用程序”进行 POST。在最后一步中,我收到 500 代码响应。我希望这与 @Matthew Proctor 所说的无关。因为我无法简单地管理服务器

最佳答案

谢谢@ShelbyZ你是对的,这是分割域的场景。现在授权有效,我可以注册我的应用程序。也为后代树立榜样

var http = require('request-promise');


var lync = {};

lync._authorize = function(){

var self = this;

var orgDomain = self.urls.user.match(/https:\/\/([\w\d\.]+)/i)[0];
//console.log(orgDomain);

http.get(self.urls.user).catch(function(err){
if(err.statusCode == 401){
var toParse = err.response.headers['www-authenticate'];
var Oauth = toParse.match(/https:\/\/[\d\w\./_-]+/i)[0];

var loginPost = {
grant_type: 'password',
username: self.username,
password: self.password
};

return http.post(Oauth, {form:loginPost});
}
}).then(function(data){
if(data) {
var parsed = JSON.parse(data);
//setup authorization
http = http.defaults({
headers: {Authorization: parsed.token_type + ' ' + parsed.access_token}
});
return http.get(self.urls.user);
}
}).then(function(data){
//check for split-domain scenario
var parsed = JSON.parse(data);
var domain = parsed._links.self.href.match(/https:\/\/([\w\d\.]+)/i)[0];
console.log('[1] '+orgDomain);
console.log('[2] '+domain);

if(domain!== orgDomain){
//split domain scenario
self.urls.user = self.urls.user.replace(orgDomain, domain);
http = http.defaults({
headers: {Authorization: null}
});

self._authorize();
} else { //create app
var parsed = JSON.parse(data);
self.urls.applications = parsed._links.applications.href;

var registerApp = {
culture : "en-us",
endpointId : "2d9dc28d-4673-4035-825c-feb64be28e4e",
userAgent : "NodeJs client"
};
return http.post(self.urls.applications, {body: registerApp, json:true});
}
}).then(function(app){
console.log(app);
});

};

lync.setup = function(email, password){
var self = this;
var hostname = email.split('@');
this.username = email;
this.password = password;

//discover urls
return http.get('http://lyncdiscover.'+hostname[1])
.then(function(d) {
var parsed = JSON.parse(d);
self.urls = {
self: parsed._links.self.href,
user: parsed._links.user.href,
xframe: parsed._links.xframe.href
};
return self._authorize();
});

};



//run app
lync.setup('username@domain.com', 'password');

关于node.js - UCWA Lync 身份验证 - 500 Web 票证无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28137363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com