【问题标题】:failed to obtain access token from angular script无法从角度脚本获取访问令牌
【发布时间】:2016-07-27 14:24:16
【问题描述】:

我正在尝试获取一些访问令牌以使用托管在远程应用程序中的一些其余 api,当我从 curl 代理和一些插件(如 Open HttpRequester)发送请求时,我成功获取了令牌,并且我成功使用了其余的接口。

但是当我尝试从 Angular 脚本函数请求令牌时,我收到了 401 未经授权的消息。

curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H  "Accept: application/json" -d "password=spring&username=roy&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp".

我不知道如何在 post angular 方法中包含 clientapp:123456 对。

这是脚本

    var app = angular.module("app", []);
    app.controller("MyController", function($scope, $http) {
        $scope.obtain_token = function() {
            $http({
                method : 'POST',
                url : 'http://clientapp:123456@localhost:8080/oauth/token',
                data: {
                        username:'roy',
                        password: 'spring',
                        client_id: 'clientapp',
                        client_secret: '123456',
                        scope: 'write'
                      },
                transformRequest: function(obj) {
                    var str = [];
                    for (var p in obj)
                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        return str.join("&");
                }}).success(function (data, status, headers, config){
                    alert(data.access_token);
                }).error(function (data, status, headers, config){
                    //alert("Errooooooooor");
                });
        };
    });

我试过你的版本,但它不起作用。

【问题讨论】:

    标签: java angularjs rest oauth-2.0 client


    【解决方案1】:

    你可以发到网址:

    http://clientapp:123456@localhost:8080/oauth/token
    

    如果使用 HTTP 身份验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-10
      • 2019-08-05
      • 2022-01-01
      • 2018-01-08
      • 2018-01-17
      • 1970-01-01
      相关资源
      最近更新 更多