如果有人对我的解决方案感兴趣:
我编写了自己的类来使用摘要身份验证:
如果有人感兴趣:(它对我有用 - 但不是完整的 HTTP Digest Auth 标准)
-> NC 和 Nonce 将在第一步由我的服务器发送从 HTML 表单读取的用户名和密码
export class AuthComponent {
loggedIn: string = "false";
sessionID: string = "n.s";
username = "";
password = "";
targetUrl: string = "<<targetUrl>>";
md5gen: Md5 = new Md5();
nc = "<<your nc>>";
nonce = "";
opaque = "";
qop = "";
realm = "";
uri = "";
cNonce = '<<your nonce>>';
constructor(private http: HttpClient, private router: Router, private toast: HotToastService)
{
this.http.get<authModel>(this.targetUrl).subscribe(res =>
{
console.log(res);
this.loggedIn = res.loggedIn;
this.nc = res.counter;
this.nonce = res.nonce;
this.opaque = res.opaque;
this.qop = res.qop;
this.realm = res.realm;
this.uri = res.uri;
this.username = res.username;
})
}
sendCredentials() {
//Create needed Hashes or auth
this.md5gen.start();
var A1 = this.md5gen.appendStr(this.username + ":" + this.realm + ":" + this.password).end();
this.md5gen.start();
var A2 = this.md5gen.appendStr("GET:" + this.uri).end();
var stuff = A1 + ":" + this.nonce + ":" + this.nc + ":" + this.cNonce + ":" + this.qop + ":" + A2;
this.md5gen.start();
var resp = this.md5gen.appendStr(stuff).end();
/*
console.log("Response: " + resp);
console.log(this.password + " -> " + A1);
console.log(resp);
console.log("---------------");
console.log("RQ-Method: " + "GET", 0);
console.log("RQ-Uri: " + res.uri, 0);
console.log("RQ-NONCE: " + res.nonce, 0 );
console.log("RQ-NC: " + this.nc, 0 );
console.log("RQ-CNONCE: " + cNonce, 0 );
console.log("RQ-QOP: " + res.qop, 0 );
*/
var header =
{
headers: new HttpHeaders(
{
'Content-Type': 'application/json; charset=utf-8',
'requestModule' : 'auth-Module',
'Authorization': 'Digest username="' + this.username + '", realm="' + this.realm + '", nonce="' + this.nonce + '", uri="' + this.uri + '", response="' + resp + '", opaque="' + this.opaque + '", qop=' + this.qop + ', nc=' + this.nc + ', cnonce="' + this.cNonce + '"',
}
)
}
this.http.get<boolean>(this.targetUrl + "/auth", header).subscribe(
res => {
if(res == true)
{
successToast(this.toast, 'Successfully loggedIn! - Welcome ' + this.username);
console.log("Logged In!");
this.router.navigate(['/']);
}
else
{
if(res == null)
{
console.log("No Data!");
}
else
{
console.log("Wrong User/Pass!");
}
errorToast(this.toast, 'Wrong password or username!');
}
},
err => console.log('HTTP Error', err),
() => console.log('HTTP request completed.')
)
}
}