curl - Keycloak 可以使用 cUrl 获取令牌,但不能使用 javascript httprequest
问题描述
在 cUrl 的帮助下,我能够从 Keycloak 获得令牌。但不是在 HTML 文件中使用带有 Javascript 的 httprequest。这里是请求数据:
fetch ('http://localhost:8080/auth/realms/MyRealm/protocol/openid-connect/token', {
method: 'post',
body: "client_id=xxx&password=yyy&username=testuser&grant_type=password&client_secret=633ebfee-5200-4cef-a12f-9196a7597334&scope=openid",
headers: {
'Content-Type': 'application/x-www-form-urlencoded
},
mode: 'no-cors'
})
答案不是令牌,而是以下对象:
body: null
bodyUsed: false
headers: Headers
ok: false
redirected: false
status: 0
statusText: ""
type: "opaque"
url: ""
HTML 文件作为 localhost 在本地 Web 服务器上运行。当我通过 Httprequest 调用它时,我需要改变什么?
解决方案
推荐阅读
- algorithm - 是否可以使用 Grover 算法进行真实数据搜索?
- sql - 使用子查询的 SQL 查询性能问题
- wordpress - Docker wordpress 多站点 - 要公开哪些端口?
- ios - 如何访问所选文件夹中的所有文件?
- r - foreach() 无法在个人文件夹中加载包
- c++ - 特征块错误的列数和行数
- r - 在闪亮的仪表板中切换选项卡后,我的 google_map 没有反应
- reactjs - 自定义 Swagger-UI 布局
- xamarin - xamarin.forms listview 由 BindingContext 和 viewmodel 填充
- javascript - 是否有一种非试错法来确定表达式是否为 `a Op b ?boolean#1 : boolean#2` 可以确定操作顺序吗?