npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jdcloud-sdk-signer

v2.0.3

Published

JD openapi sdk 签名算法

Downloads

19

Readme


JavaScript Style Guide

简介

该项目实现京东云API网关签名的生成,适用于API网关产品,也可用于OpenAPI的签名生成。

环境准备

1.京东云Node.js SDK适用于Node.js 8.6.0及以上,npm 5.6.0及以上。

2.在开始调用京东云open API之前,需提前在京东云用户中心账户管理下的AccessKey管理页面申请accesskey和secretKey密钥对(简称AK/SK)。AK/SK信息请妥善保管,如果遗失可能会造成非法用户使用此信息操作您在云上的资源,给你造成数据和财产损失。

SDK使用方法

建议使用npm安装京东云Node.js SDK,如下所示:

npm install jdcloud-sdk-signer

您还可以下载sdk源代码自行使用。

SDK使用中的任何问题,欢迎您在Github SDK使用问题反馈页面交流。

注意:京东云并没有提供其他下载方式,请务必使用上述官方下载方式!

调用示例

const {Signer,Context}=require('../src')
let ctx=new Context('192.168.180.18','/v1/regions/cn-north-1/buckets','GET',null,'oss')  //可直接讲req.headers 传入
ctx.regionId='cn-north-1'
ctx.query=ctx.buildQuery({a:1})
ctx.headers.set('content-type','application/json')
ctx.buildNonce()

let credentials= {
    accessKeyId : 'accessKeyId',
    secretAccessKey: 'secretAccessKey'
}

let signer=new Signer(ctx,credentials)
signer.setSignableHeaders([
  'content-type',
  'host',
  'x-jdcloud-date',
  'x-jdcloud-nonce'
])
let auth= signer.sign(new Date())
ctx.headers.set('Authorization',auth)
console.log("GET签名为:",auth)

console.log('------------------------')

ctx.query=null
ctx.body=JSON.stringify({a:1,b:2})
ctx.method='POST'
signer=new Signer(ctx,credentials)
auth= signer.sign(new Date())
console.log("POST签名为:",auth)

将生成的签名,传递到header里作为Authorization的值,即可进行调用。

注意事项

  1. 设置请求上下文Context(仅作请求签名的载体,不发请求),如host,path,method,headers,serviceName(默认为''),具体参见构造函数(ts 定义)。其中header必须包含:x-jdcloud-nonce、x-jdcloud-date(格式:20190101T010101Z)。
  2. query需要调用buildQuery 方法处理
  3. 初始化Signer,设置ak/sk和logger(默认为console),执行方法得到签名