RESTサービスで簡単なAPIアプリケーションを構築しました。 Azure App Serviceでプリンシパル認証を有効にしました。私はC#のコードで私のベアラトークンを取得することができるよ:APIアプリケーションのAzureサービスプリンシパル認証
public static AuthenticationResult GetS2SAccessTokenForProdMSA()
{
return GetS2SAccessToken(authority, resource, clientId, clientSecret);
}
static AuthenticationResult GetS2SAccessToken(string authority, string resource, string clientId, string clientSecret)
{
var clientCredential = new ClientCredential(clientId, clientSecret);
AuthenticationContext context = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = context.AcquireTokenAsync(resource, clientCredential).Result;
return authenticationResult;
}
私にはJavaScriptで私のベアラトークンを取得したい場合は、例えば:
$.ajax({
url: 'https://login.microsoftonline.com/1640e15a-2d4c-4903-8b89-a00c52ac3c17/oauth2/token',
type: 'POST',
crossOrigin: true,
data: 'resource=https://foobar' +
'&client_id=68b9a002-d6f9-4732-9c9c-893b2c60ba42' +
'&client_secret=<secret>' +
'&grant_type=client_credentials',
contentType: 'application/x-www-form-urlencoded',
success: function (returndata) {
alert(formData);
},
error: function (errordata) {
alert(errordata.statusText);
}
});
私が言っChromeでエラーが発生します。
を上に存在しますいいえ「アクセス制御 - 許可原点」ヘッダは、要求されたリソース
しかし、フィドラーで私はベアラートークンで成功した答えを見ることができます(Firefoxでは同じエラーですが、IE 11ではそうではありません)。
なぜAJAXリクエストによってトークンを要求することはできませんか?
何か不足していますか?
いいえお問い合わせ
ウェブページとは別のドメインにリクエストしているので、[サーバーでCORSを許可する]必要があります(http://stackoverflow.com/questions/20035101/no-access-control-allow-origin -header-present-on-the-requested-resource) – stuartd
APIアプリケーション自体でCORSを有効にしました。しかし、URLでCORSを有効にする方法はありますかhttps://login.microsoftonline.com/1640e15a-2d4c-4903-8b89-a00c52ac3c17/oauth2/token? – user2191213
私は、なぜ私がどのURLからのベアラトークンを要求できないのか分かりません。 – user2191213