当我尝试向我的spring服务器调用"oauth/token"端点进行身份验证时,我遇到了CORS问题.服务器以401响应回答
XMLHttpRequest cannot load http://localhost:8080/oauth/token.
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8000' is therefore not allowed access.
The response had HTTP status code 401.
Run Code Online (Sandbox Code Playgroud)
这就是我如何调用服务器:
login: function(credentials) {
var data = "username=" + encodeURIComponent(credentials.username) + "&password="
+ encodeURIComponent(credentials.password) + "&grant_type=password&scope=read%20write&" +
"client_secret=mySecretOAuthSecret&client_id=awhyapp";
return $http.post('http://localhost:8080/oauth/token', data, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Basic " + Base64.encode("awhyapp" + ':' + "mySecretOAuthSecret")
}
}).success(function (response) { …Run Code Online (Sandbox Code Playgroud)