Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Need to specify encoding on decode.

オープン
#72 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, node.js
領域
api

調査の方向性

まず jws.decode エントリーポイントと既存の encode/decode の動作を確認してください。payload ではサポート対象の encoding オプションと base64-url workaround が示されていますが、ファイルパスやテストパスは示されていません。decode が要求された encoding の動作をサポートし、示されている header、payload、signature の結果を維持し、base64 と JSON の例をカバーできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

My JWS payload is some raw bytes, which I pass to the encode function as base64, using the supported "base64" encoding option:

jws.sign({
  header: {
    alg: "HS256"
  },
  payload: "myPayloadBase64=",
  secret: "secret",
  encoding: "base64"
})
// 'eyJhbGciOiJIUzI1NiJ9.myPayloadBase64.rFU9W9o-1Mw3jEudDOFjQZHrxOOmMZdTRnLbXTL2VY8'

When I decode this, there's no corresponding option to decode directly to base64. Decode gives me a string using the encoded bytes, but it contains some escaped character values and is not compatible with Buffer:

const decodedPayload = jws.decode('eyJhbGciOiJIUzI1NiJ9.myPayloadBase64.rFU9W9o-1Mw3jEudDOFjQZHrxOOmMZdTRnLbXTL2VY8')
// '�#��Z\u001at\u0016�{�'

Buffer.from(decodedPayload, "utf8").toString("base64")
//'77+9I++/ve+/vVoadBbvv71777+9'
// should be 'myPayloadBase64='

My workaround right now is to not use decode at all. Instead, I just split('.')[1] and then require('base64-url') to decode the bytes or convert it to normal base64.

It would be much easier if I were able to pass the encoding I used to the decode method to get my base64 (or whatever other encoding) directly.

jws.decode(jwsStr, "base64" /* any supported encoding */)
/*
  {
    header: { alg: "HS256" },
    payload: "myPayloadBase64=",
    signature: "rFU9W9o-1Mw3jEudDOFjQZHrxOOmMZdTRnLbXTL2VY8"
  }
*/

As an additional feature suggestion, this would also let people ask decode to automatically parse JSON payloads:

const encoded = jws.sign({header:{alg: "HS256"}, payload: {test: "value"}, secret: "secret"})
jws.decode(encoded, "json")
// {test: 'value'}
主要言語
JavaScript
スター
720
フォーク
136
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

auth0/node-jws のほかの issue

auth0/node-jws の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。