みなさん、こんにちは。私はいくつかの問題を解決しようとしています。
クレデンシャルを使用して、いくつかのデータを取得する必要があります。
POSTMANで、Auth Basic Authorizationを使用してデータを取得しますが、ブラウザで実行されるコードで試してみると、コンソール「TypeError:Failed to fetch」が表示され、ネットワークで取得します。ステータス「CORSエラー」。
これはコードです:
fetch(
'https://content-us-8.content-cms.com/api/f8d92c5b-2ec6-46ee-8e22-cd2d9a556473/authoring/v1/content/views/by-type?id=5030aaad-9bf6-45db-9a3e-5cc7cd190103',
{
headers: {
Authorization: 'Basic ' + base64.encode(userName + ':' + password)
},
withCredentials: true
}
)
.then((el) => el.json())
.then((el) => console.log(el))
.catch((err) => console.log(err))
.finally((el) => {
console.log('FINALLY');
console.log(el);
});
ヘッダーなしで呼び出しを行うと、次のエラーが発生します。
{
"requestId": "807bd27d2b28962b9d2834458e926499",
"service": "prod-infra-api-dispatcher",
"version": "0.0.1883",
"description": "Acoustic Content, API Dispatcher Component",
"errors": [
{
"name": "AccessControlError",
"message": "The user 'undefined' tried to perform GET /content/views/by-type with tenant 'f8d92c5b-2ec6-46ee-8e22-cd2d9a556473'. Access to the service was denied because the user roles 'anonymous' do not match the accepted roles 'admin,manager,editor,viewer'. Verify that the user has the correct role assigned.",
"locale": "en",
"parameters": {
"statusCode": 403,
"method": "GET",
"path": "/content/views/by-type",
"roles": [
"anonymous"
],
"requiredRoles": [
"admin",
"manager",
"editor",
"viewer"
],
"timestamp": 1650811022658
},
"timestamp": "Sun, 24 Apr 2022 14:37:02 GMT"
}
],
"timestamp": "Sun, 24 Apr 2022 14:37:02 GMT",
"message": "The user 'undefined' tried to perform GET /content/views/by-type with tenant 'f8d92c5b-2ec6-46ee-8e22-cd2d9a556473'. Access to the service was denied because the user roles 'anonymous' do not match the accepted roles 'admin,manager,editor,viewer'. Verify that the user has the correct role assigned."
}
クレデンシャルを設定していないためにこのエラーが発生することを理解しています...しかし、これを達成するために複数の方法を試しましたが、成功しませんでした。
Authorization
ブラウザは、先行するプリフライトリクエストが成功した場合にのみ、ヘッダーを使用してクロスオリジンGETリクエストを作成します。しかし、あなたが試してみることができるようにcurl
:
>curl -I -X OPTIONS -H "Access-Control-Request-Headers:Authorization"
-H "Origin:http://localhost"
https://content-us-8.content-cms.com/api/...
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: http://localhost
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,OPTIONS
Access-Control-Allow-Headers: accept,accept-language,content-language,pragma,cache-control,x-xsrf-token,x-acoustic-region,x-acoustic-auth-source,x-ibm-dx-tenant-id,x-cms-user-auth,x-ibm-dx-user-auth
Access-Control-Expose-Headers: cache-control,content-language,content-type,expires,last-modified,pragma,x-ibm-dx-request-id,x-response-time
Authorization
ヘッダーが許可されたヘッダーのリストにありません。言い換えると、このサービスでは、クロスオリジンリクエストでの基本認証は許可されていません。
content-cms.com
許可されたヘッダーになるようにバックエンドに影響を与えることができない場合Authorization
、唯一のオプションは、独自のバックエンドサーバーを介してリクエストをトンネリングすることです。それとも「サーバーレス」でプログラミングしていますか?
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加