11 Star 2 Fork 6

OpenHarmony-SIG/ohos_jsonwebtoken

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

@ohos/jsonwebtoken

介绍

JSON Web Token(JWT)是一个开放的行业标准(RFC 7519),它定义了一种简洁的、自包含的协议格式,用于在通信双方传递json对象,传递的信息经过数字签名可以被验证和信任。@ohos/jsonwebtoken是一款适用于 openharmony 环境的 Json Web Token实现。本库基于 jsonwebtoken原库 v9.0.1 版本进行适配。

下载安装

ohpm install @ohos/jsonwebtoken

OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm 包

使用说明

基本使用示例

  1. 同步签名 ( 默认算法:HMAC SHA256 )

    import jwt from "@ohos/jsonwebtoken";
    var token = jwt.sign({ foo: 'bar' }, 'shhhhh');
  2. 异步签名

    jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }, function(err, token) {
      console.log(token);
    });
  3. RSA SHA256算法,使用私钥同步签名

    // sign with RSA SHA256
    var privateKey = "";
    var token = jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' });
  4. RSA SHA256算法,使用公钥验证签名

    var publicKey = ""
    const decoded =  jwt.verify(signatrue,publicKey);

接口

模块名 功能 备注
sign(payload,secret,options) 签名
verify(signature,publicKey) 验签

更多模块的使用可参考官方文档,单元测试用例详情见TEST.md

约束与限制

在下述版本验证通过:DevEco Studio: 4.0 Canary2(4.0.1.400), SDK: API10 (4.0.0.24) Beta1

贡献代码

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

开源协议

本项目基于 Apache License 2.0 ,请自由地享受和参与开源。

The MIT License (MIT) Copyright (c) 2015 Auth0, Inc. <support@auth0.com> (http://auth0.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
TypeScript 等 3 种语言
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-sig/ohos_jsonwebtoken.git
git@gitee.com:openharmony-sig/ohos_jsonwebtoken.git
openharmony-sig
ohos_jsonwebtoken
ohos_jsonwebtoken
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891