私は、リクエストを処理するためにaxios
ライブラリを使用しているReactアプリを持っています。だから、次の投稿次oauth2からのマイクロソフトのログイン
How to login with username/password using OAuth2 and microsoft login and HTTP request
私はポストマンのアクションを実行することができます。
は、その後、私はPOST
const dataForBody = `${'grant_type=password&' +
'username='}${encodeURI(userName)}&` +
`password=${encodeURI(userPassword)}&` +
`client_id=${encodeURI(clientID)}&` +
`resource=${encodeURI('https://graph.microsoft.com')}&` +
`client_secret=${encodeURI(clientSecret)}`;
const messageHeaders = {
'Content-Type': 'application/x-www-form-urlencoded'
};
axios({
method: 'post',
url: 'https://login.microsoftonline.com/{tenant}/oauth2/token',
headers: messageHeaders,
data: dataForBody,
})
.then((response) => {
});
を実行するためにaxiosライブラリを設定するが、私は次のエラーを取得:
'Access-Control-Allow-Origin': 'https://login.microsoftonline.com',
をヘッダーに:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://login.microsoftonline.com/ {tenant}/oauth2/token. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
を私が追加してみましたしかし、それは動作しませんでした。
Allow-Control-Allow-Origin: *
クロムエクステンションを追加すると問題が解決しました。
私のアプリは紺碧の上に公開されるので、他のウェブブラウザでリクエストをテストしたところ、うまくいきませんでした。だから、私はユーザーに拡張機能をインストールさせたくない。
私のリクエストに何か問題がありますか?なぜ郵便配達員はヘッダーを設定しないとできますか?
これを達成する他の方法はありますか?
PS:私はadal.js
を使用していると読んでいますが、私はユーザーのことを知っているのでアプリを渡してしまい、手動ログインを避けたいと思っています。