小编san*_*a4l的帖子

在Spring服务器中使用OAuth身份验证的CORS失败

当我尝试向我的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)

oauth cors angularjs spring-boot jhipster

6
推荐指数
1
解决办法
1398
查看次数

标签 统计

angularjs ×1

cors ×1

jhipster ×1

oauth ×1

spring-boot ×1