我面临一个奇怪的问题,涉及SPA网站(内联网)上的集成Windows身份验证
登录流程如下:
一些评论:
客户端(我将fetch用作其他所有内容,我将其改写为经典方法以消除可能的干扰,无济于事):
public async logIn(): Promise<boolean> {
return new Promise(function (resolve, reject) {
var http = new XMLHttpRequest();
var url = `${environment.baseUrl}/token`;
var params = 'grant_type=password&username=&password=';
http.open('POST', url, true);
http.withCredentials = true;
//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = () => {
if (http.readyState == 4 && http.status == 200) {
let result = JSON.parse(http.responseText);
alert(http.responseText);
if (result.access_token) {
localStorage.setItem(EMPLOYEEID, result.employeeId);
localStorage.setItem(ROLES, result.roles);
localStorage.setItem(TOKEN, result.access_token);
localStorage.setItem(
TOKENEXPIRY,
moment()
.add(result.expires_in, "seconds")
.toJSON()
);
return resolve(true);
} else return resolve(false);
}
}
http.send(params);
})
}
public enableSilentTokenRenew() {
setTimeout(async () => {
await this.logIn(); //this fails
this.enableSilentTokenRenew();
}, moment(localStorage.getItem(TOKENEXPIRY)).diff(moment(), "millisecond") - 10000);
}
服务器:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var adUser = context.OwinContext.Request.User.Identity // this is null the second time