当使用资源所有者密码流时,如何使用带有IdentityServer4的fetch来获取JWT令牌?(大多数情况下不建议这样做)。
首先,您可以在这里找到有用的信息来实施您的解决方案:
但是如何使用[fetch api]从IdentityServer 4获取令牌呢?
const form = new FormData();
form.append('grant_type', 'password');
form.append('username', username);
form.append('password', password);
if (this._settings.scope) {
form.append('scope', this._settings.scope);
}
form.append('client_id', this._settings.clientId);
if (this._settings.clientSecret) {
form.append('client_secret', this._settings.clientSecret);
}
var options = {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
rejectUnauthorized: false, // when use local unverified certificate
body: form
};
我应该收到一个JWT令牌作为响应,但我收到了一个http 500错误。“内部服务器错误”
如果我用fiddler跟踪HTTP头,我会得到以下结果:
POST http://127.0.0.1:8888/ HTTP/1.1
content-type: multipart/form-data
accept-encoding: gzip,deflate
user-agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)
connection: close
accept: */*
content-length: 896
Host: 127.0.0.1:8888