리소스 소유자 비밀번호 흐름을 사용할 때 IdentityServer4와 함께 fetch를 사용하여 JWT 토큰을 얻는 방법은 무엇입니까? (대부분 권장되지는 않음).Identity Server 4와 함께 페치 사용
암시 적 플로우를 사용해야하는 경우에도 내 스파 적용을 위해 제 상황에서보다 편리하기 때문에이 플로우를 사용하고 싶습니다. 먼저 , 당신은 당신의 솔루션을 구현하기 위해 여기에 유용한 정보를 찾을 수 있습니다 :
을하지만 사용하는 방법 [가져-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 오류가 발생합니다. "내부 서버 오류"
내가 피들러와 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
identityserver 로그의 내용은 무엇입니까? – cheesemacfly
'dbug : IdentityServer4.Validation.PostBodySecretParser [0] 후 몸 치명타 비밀에 대한 분석을 시작 : IdentityServer4.Hosting.IdentityServerMiddleware를 [0] 처리되지 않은 예외 : System.IO.InvalidDataException : ** 내용 유형 경계가 없습니다. ** Microsoft.AspNetCore.Http.Features.FormFeature.GetBoundary (MediaTypeHeaderValue의 contentType, INT32 lengthLimit) Microsoft.AspNetCore.Http.Features.FormFeature에서 에서. d__18.MoveNext() --- 예외가 발생한 이전 위치에서 스택 추적 끝 --- –
Armand
"헤더"에서 "content-type"을 제거하면 작동합니다! 나중에 답을 줄뿐만 아니라이 코드는 요청 js 모듈과 함께 작동하는 복사/붙여 넣기에서 나온 것입니다. (전달 된 content-type을 덮어 쓰기 요청) – Armand