How to set auth token in http header in angular js resource get

╄→尐↘猪︶ㄣ 提交于 2019-12-25 16:25:43

问题


I am trying to access rest api which needed a Oauth 1.0a authentication. Currently I have api key, access token. How to set Authorization with access token to access api in following code snippet.

  1. How syntax looks like for Authorization with access token
  2. what are necessary attributes needs to be set
  3. Is there any region issues can exist for api access?
  4. when it shows No 'Access-Control-Allow-Origin' header is present on the requested resource. Error

I am trying to set http header in following code snippet,

$resource('url', {}, {
                "getData": {
                    method: "GET",
                    headers: {
                                'Content-Type': 'application/json',
                                //? 
                            }
                }
            });

Thank you.


回答1:


Let's say that your access token is called Token. Your header should looks like this:

headers: {
    'Authorization': 'Token QWxhZGRpbjpvcGVuIHNlc2Ff(Key example)'}
}


来源:https://stackoverflow.com/questions/28912506/how-to-set-auth-token-in-http-header-in-angular-js-resource-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!