Skip to content

Commit

Permalink
feat: add AuthorizationHeader function, APP KEY, ID
Browse files Browse the repository at this point in the history
  • Loading branch information
bo cheng committed Nov 2, 2021
1 parent 74d6a7d commit 6b8e67d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"jssha": "^3.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
Expand Down
14 changes: 14 additions & 0 deletions src/api/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import jsSHA from 'jssha'

export const getAuthorizationHeader = () => {
const UTCTime = new Date().toUTCString()
const ShaObj = new jsSHA('SHA-1', 'TEXT')
ShaObj.setHMACKey(process.env.REACT_APP_TDX_APP_KEY || '', 'TEXT')
ShaObj.update('x-date: ' + UTCTime)
let HMAC = ShaObj.getHMAC('B64')
let Authorization = 'hmac username="' + process.env.REACT_APP_TDX_APP_ID + '", algorithm="hmac-sha1", headers="x-date", signature="' + HMAC + '"'
return {
Authorization,
'X-Date': UTCTime
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": [
"dom",
"dom.iterable",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7027,6 +7027,11 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

jssha@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/jssha/-/jssha-3.2.0.tgz#88ec50b866dd1411deaddbe6b3e3692e4c710f16"
integrity sha512-QuruyBENDWdN4tZwJbQq7/eAK85FqrI4oDbXjy5IBhYD+2pTJyBUWZe8ctWaCkrV0gy6AaelgOZZBMeswEa/6Q==

"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82"
Expand Down

0 comments on commit 6b8e67d

Please sign in to comment.