weixin_33736832 2016-09-08 14:00 采纳率: 0%
浏览 26

Oauth2和Iron-Ajax

I need to implement Oauth2 identification in my polymer app, but i'm struggling with the iron-ajax. I want to provide the token through headers.

This is what I did:

<iron-ajax id="usersAjax"
        auto
         url="https://myawesomeurl.com/api/users"
         method="GET"
         handle-as="json"
         headers="[[oauthToken]]"
         last-response="{{usersList}}"></iron-ajax>

and the script:

oauthToken: {
    type: "function",
    value: function () {
        var token = Cookies.get("Authorization");
        var tokenString = {'Authorization': 'Bearer ' + token};
        console.log("Oauth2 token: ", tokenString);
        return tokenString;
    }
  }

ubt when I run it, it just fail. It cannot connect to the server because it expect a "GET" method, but it is automatically changed into "OPTION" according to the console:

OPTIONS https://myawesomeurl.com/api/users net::ERR_CONNECTION_REFUSED

In chrome dev tools > network, it says:

Provisional headers are shown Access-Control-Request-Headers:authorization Access-Control-Request-Method:GET Origin:http://localhost:8080 Referer:http://localhost:8080/admin-users User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Any ideas??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!