简体   繁体   English

如何使用Javascript设置授权HTTP标头

[英]How to Set Authorization HTTP Header with Javascript

I'm using oauth in an API library and the API requires that the Authorization header be explicitly set for each request. 我在API库中使用oauth,API要求为每个请求显式设置Authorization标头。

I'm familiar with the setRequestHeader method, using it like: 我熟悉setRequestHeader方法,使用它像:

this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

However, I'm not sure how to properly set the Authorization header, since it has so many parameters. 但是,我不确定如何正确设置Authorization标头,因为它有如此多的参数。 An example of what the header needs to look like is: 标题需要的示例如下:

Authorization: OAuth realm="",oauth_version="1.0",oauth_consumer_key="consumer",oauth_token="foo",oauth_timestamp="timestamp",oauth_nonce="ononce",oauth_signature_method="PLAINTEXT",oauth_signature="osig"

How do I properly set the Authorization header in this format using setRequestHeader? 如何使用setRequestHeader以此格式正确设置Authorization标头? Thanks! 谢谢!

Use the OAuth javascript library. 使用OAuth javascript库。 It's setup to build those signed OAuth headers for you... 它的设置是为您构建那些签名的OAuth标头...

http://oauth.googlecode.com/svn/code/javascript/ http://oauth.googlecode.com/svn/code/javascript/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM