【问题标题】:Making OAuth2 request in angularjs在angularjs中发出OAuth2请求
【发布时间】:2017-06-22 03:27:22
【问题描述】:

我正在尝试在 angularjs 中发出请求以检索访问令牌,但我不是 100% 确定如何去做。这是 curl 中的请求

curl -X POST -d “grant_type=密码&用户名=&密码=&范围=读取” -u":" http://localhost:8000/o/token/

感谢所有帮助

【问题讨论】:

    标签: angularjs curl oauth2


    【解决方案1】:

    我认为您需要使用查询字符串参数发布

    为此,您需要在您的发布请求中进行一些修改

    var request = $http({
                        method: "POST",
                        url: "",
                        transformRequest: transformRequestAsFormPost,
                        data: {
                            grant_type: "password",
                            username: "Kim",
                            password: "123",
                            scope: "read"
                        }
                    });
    

    这里有更详细的解释https://www.bennadel.com/blog/2615-posting-form-data-with-http-in-angularjs.htm

    【讨论】:

      【解决方案2】:

      我想通了

      var data = "grant_type=password" + "&username="+cred.username + "&password="+cred.password +
                  "&client_id=" + cred.client_id +
                  "&client_secret=" + cred.client_secret;
             $http({
                 method: 'POST',
                 url: 'BaseUrl',
                 data: data,
                 headers: {'Content-Type': 'application/x-www-form-urlencoded'}
      
             })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-23
        • 1970-01-01
        • 1970-01-01
        • 2015-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多