Ionic framework 爱奥尼亚+;Jhipster oauth2错误无访问控制
一直在尝试将Jhipsters oauth2登录与localhost上的ionic应用程序一起使用,并不断获得: 选项(匿名函数)@ionic.bundle.js:23826sendReq@ionic.bundle.js:23645serverRequest@ionic.bundle.js:23357processQueue@ionic.bundle.js:27879(匿名函数)@ionic.bundle.js:27895Scope.$eval@ionic.bundle.js:29158Scope.$digest@ionic.bundle.js:28969Scope.$apply@ionic.bundle.js:29263(匿名函数)@ionic.bundle.js:36615eventHandler@ionic.bundle.js:16583triggerMouseEvent@ionic.bundle.js:2948tapClick@ionic.bundle.js:2937tapMouseUp@ionic.bundle.js:3013 ?ionicplatform=android:1 无法加载XMLHttpRequest。对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许来源”标头。因此,不允许访问源“”。响应的HTTP状态代码为401。 ?ionicplatform=android:1 无法加载XMLHttpRequest。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“” 我已经尝试添加谷歌插件,没有改变任何事情。确保 .antMatchers(HttpMethod.OPTIONS,“/**”).permitAll() 他在背景中Ionic framework 爱奥尼亚+;Jhipster oauth2错误无访问控制,ionic-framework,token,jhipster,Ionic Framework,Token,Jhipster,一直在尝试将Jhipsters oauth2登录与localhost上的ionic应用程序一起使用,并不断获得: 选项(匿名函数)@ionic.bundle.js:23826sendReq@ionic.bundle.js:23645serverRequest@ionic.bundle.js:23357processQueue@ionic.bundle.js:27879(匿名函数)@ionic.bundle.js:27895Scope.$eval@ionic.bundle.js:29158Scop
还有什么我遗漏的吗?尝试在应用程序.yml中取消注释cors
cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
要使用Oauth2身份验证在爱奥尼亚中访问REST API,您必须首先通过以下方式在爱奥尼亚应用程序中获取令牌:
$http({
method: "post",
url: "http://192.168.0.4:8085/[Your app name]/oauth/token",
data: "username=admin&password=admin&grant_type=password&scope=read write&client_secret=my-secret-token-to-change-in-production&client_id=auth2Sconnectapp",
withCredentials: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'Authorization': 'Basic ' + 'YXV0aDJTY29ubmVjdGFwcDpteS1zZWNyZXQtdG9rZW4tdG8tY2hhbmdlLWluLXByb2R1Y3Rpb24='
}
})
.success(function(data) {
alert("success: " + data);
})
.error(function(data, status) {
alert("ERROR: " + data);
});
此处“YXV0aDJTY29ubmVjdGFwcDpteS1zZWNyZXQtdG9rZW4tdG8tY2hhbmdlLWluLXByb2R1Y3Rpb24=”等于(clientId+:“+clientSecret)--所有base64编码
您可以使用为自己验证或重新创建它
如果成功,aboue$http将为您提供此JSON
{
"access_token": "2ce14f67-e91b-411e-89fa-8169e11a1c04",
"token_type": "bearer",
"refresh_token": "37baee3c-f4fe-4340-8997-8d7849821d00",
"expires_in": 525,
"scope": "read write"
}
如果您想访问任何API,请注意“访问令牌”和“令牌类型”,这是您必须使用的
比如说
$http({
method: "get",
url: "http://192.168.0.4:8085/auth-2-sconnect/api/countries",
withCredentials: true,
headers: {
'Authorization':' [token_type] + [space] + [access_token] '
}
})
.success(function(data) {
alert("success: " + data);
})
.error(function(data, status) {
alert("ERROR: " + data);
});