0

임 현재 https://login.microsoftonline.com/XXX/oauth2/token 엔드 포인트로 게시물 요청을 보내어 애플리케이션의 액세스 토큰과 새로 고침 토큰을 검색하려고합니다. axios를 사용하여 포스트 요청을 엔드 포인트로 보낼 때 프리 플라이트는 송신되지 않지만 응답은 리턴되지 않습니다.Azure AD 프리 플라이트 요청에서 데이터를 반환하지 않습니다.

오류가 : 그러나 Axios의 POST 요청에 대한 다른 접근 방법을 사용하여

Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:3000' is therefore not allowed access. 

, 데이터를 반환하지만 프리 플라이트가 없습니다와 다른 오류 제공 :

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:3000' is therefore not allowed access. 

두 Axios의 요청을 :

const data = new FormData(); 

data.append('grant_type', this.config.grant_type); 
data.append('client_id', this.config.client_id); 
data.append('code', localStorage.getItem('auth_code')); 
data.append('redirect_uri', this.config.redirect_uri); 
data.append('client_secret', this.config.client_secret); 
data.append('resource', this.config.client_id); 

axios.post(`https://login.microsoftonline.com/${this.config.tenant}/oauth2/token`, data); 

방법 2 :

,
axios({ 
    method: 'post', 
    contentType: 'application/json', 
    url: `https://login.microsoftonline.com/${this.config.tenant}/oauth2/token`, 
    data: { 
    grant_type: this.config.grant_type, 
    client_id: this.config.client_id, 
    code: localStorage.getItem('auth_code'), 
    redirect_uri: this.config.redirect_uri, 
    client_secret: this.config.client_secret, 
    resource: this.config.client_id 
    } 
}); 

axios 요청 자체 또는 엔드 포인트에 문제가 있습니까?

답변

0

액세스 토큰을 얻으려면 암시 ​​적 허용 플로우를 사용해야합니다. 프런트 엔드 자바 스크립트에서 인증 코드 흐름을 사용할 수 없습니다!

Your client secret (AKA your app's password) is currently public to anyone who visits your site!

당신은 프런트 엔드 자바 스크립트에서 클라이언트의 비밀을 사용할 수 없습니다.

당신은 응용 프로그램의 매니페스트에서 암시 적 흐름을 가능하게 한 다음 앱에서이 같은 URL로 푸른 광고에 리디렉션을해야합니다

:

https://login.microsoftonline.com/tenant-id-here/oauth2/authorize?client_id=your-client-id&response_type=id_token+token&resource=resource-id-for-api&redirect_uri=your-app-redirect-url 

문서 : https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#single-page-application-spa

관련 문제