ai 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +10 -24
- package/dist/ai-stream.d.ts +18 -0
- package/dist/ai-stream.js +132 -0
- package/dist/ai-stream.mjs +13 -0
- package/dist/anthropic-stream.d.ts +5 -0
- package/dist/anthropic-stream.js +133 -0
- package/dist/anthropic-stream.mjs +8 -0
- package/dist/chunk-265FSSO4.mjs +91 -0
- package/dist/chunk-2L3ZO4UM.mjs +45 -0
- package/dist/chunk-GT4HKF2X.mjs +33 -0
- package/dist/chunk-JGDC3BXD.mjs +22 -0
- package/dist/chunk-NK2CVBLI.mjs +38 -0
- package/dist/chunk-PEYAHBDF.mjs +43 -0
- package/dist/chunk-TJMME6CL.mjs +24 -0
- package/dist/huggingface-stream.d.ts +5 -0
- package/dist/huggingface-stream.js +121 -0
- package/dist/huggingface-stream.mjs +8 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +278 -0
- package/dist/index.mjs +35 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.js +12 -0
- package/dist/index.test.mjs +10 -0
- package/dist/langchain-stream.d.ts +12 -0
- package/dist/langchain-stream.js +102 -0
- package/dist/langchain-stream.mjs +8 -0
- package/dist/openai-stream.d.ts +5 -0
- package/dist/openai-stream.js +144 -0
- package/dist/openai-stream.mjs +8 -0
- package/dist/streaming-text-response.d.ts +17 -0
- package/dist/streaming-text-response.js +75 -0
- package/dist/streaming-text-response.mjs +9 -0
- package/package.json +78 -29
- package/react/dist/chunk-5PP6W52J.mjs +202 -0
- package/react/dist/chunk-6EH3SWMP.mjs +55 -0
- package/react/dist/chunk-PW6HSU2N.mjs +154 -0
- package/react/dist/index.d.ts +3 -0
- package/react/dist/index.js +424 -0
- package/react/dist/index.mjs +12 -0
- package/react/dist/types-f862f74a.d.ts +123 -0
- package/react/dist/use-chat.d.ts +42 -0
- package/react/dist/use-chat.js +276 -0
- package/react/dist/use-chat.mjs +8 -0
- package/react/dist/use-completion.d.ts +47 -0
- package/react/dist/use-completion.js +229 -0
- package/react/dist/use-completion.mjs +8 -0
- package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
- package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
- package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
- package/svelte/dist/index.d.ts +4 -0
- package/svelte/dist/index.js +808 -0
- package/svelte/dist/index.mjs +11 -0
- package/svelte/dist/types-f862f74a.d.ts +123 -0
- package/svelte/dist/use-chat.d.ts +39 -0
- package/svelte/dist/use-chat.js +680 -0
- package/svelte/dist/use-chat.mjs +7 -0
- package/svelte/dist/use-completion.d.ts +38 -0
- package/svelte/dist/use-completion.js +640 -0
- package/svelte/dist/use-completion.mjs +7 -0
- package/.npmignore +0 -15
- package/.travis.yml +0 -4
- package/README.md +0 -21
- package/bin/ai.js +0 -22
- package/index.js +0 -37
- package/node_modules/request/.npmignore +0 -2
- package/node_modules/request/.travis.yml +0 -12
- package/node_modules/request/CHANGELOG.md +0 -954
- package/node_modules/request/LICENSE +0 -55
- package/node_modules/request/README.md +0 -421
- package/node_modules/request/index.js +0 -166
- package/node_modules/request/lib/cookies.js +0 -40
- package/node_modules/request/lib/copy.js +0 -8
- package/node_modules/request/lib/debug.js +0 -7
- package/node_modules/request/lib/getSafe.js +0 -34
- package/node_modules/request/lib/optional.js +0 -5
- package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
- package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
- package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
- package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
- package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/forever-agent/README.md +0 -4
- package/node_modules/request/node_modules/forever-agent/index.js +0 -119
- package/node_modules/request/node_modules/forever-agent/package.json +0 -46
- package/node_modules/request/node_modules/form-data/License +0 -19
- package/node_modules/request/node_modules/form-data/Readme.md +0 -175
- package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
- package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
- package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
- package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
- package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
- package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +0 -38
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +0 -21
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +0 -14
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +0 -15
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +0 -18
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
- package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
- package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
- package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
- package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
- package/node_modules/request/node_modules/form-data/package.json +0 -80
- package/node_modules/request/node_modules/hawk/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/README.md +0 -625
- package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
- package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
- package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
- package/node_modules/request/node_modules/hawk/index.js +0 -1
- package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
- package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
- package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
- package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
- package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
- package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
- package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
- package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
- package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
- package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
- package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
- package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
- package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
- package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
- package/node_modules/request/node_modules/hawk/package.json +0 -70
- package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
- package/node_modules/request/node_modules/hawk/test/client.js +0 -206
- package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
- package/node_modules/request/node_modules/hawk/test/index.js +0 -316
- package/node_modules/request/node_modules/hawk/test/message.js +0 -246
- package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
- package/node_modules/request/node_modules/hawk/test/server.js +0 -686
- package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
- package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
- package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
- package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
- package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
- package/node_modules/request/node_modules/http-signature/README.md +0 -75
- package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
- package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
- package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
- package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
- package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
- package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
- package/node_modules/request/node_modules/http-signature/package.json +0 -54
- package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
- package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
- package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
- package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
- package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
- package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
- package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
- package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
- package/node_modules/request/node_modules/mime-types/Makefile +0 -9
- package/node_modules/request/node_modules/mime-types/README.md +0 -101
- package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
- package/node_modules/request/node_modules/mime-types/component.json +0 -16
- package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
- package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
- package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
- package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
- package/node_modules/request/node_modules/mime-types/package.json +0 -69
- package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
- package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
- package/node_modules/request/node_modules/node-uuid/README.md +0 -207
- package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
- package/node_modules/request/node_modules/node-uuid/component.json +0 -18
- package/node_modules/request/node_modules/node-uuid/package.json +0 -54
- package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
- package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
- package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
- package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
- package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
- package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
- package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
- package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
- package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
- package/node_modules/request/node_modules/qs/.jshintignore +0 -1
- package/node_modules/request/node_modules/qs/.jshintrc +0 -10
- package/node_modules/request/node_modules/qs/.npmignore +0 -18
- package/node_modules/request/node_modules/qs/.travis.yml +0 -4
- package/node_modules/request/node_modules/qs/LICENSE +0 -28
- package/node_modules/request/node_modules/qs/Makefile +0 -8
- package/node_modules/request/node_modules/qs/Readme.md +0 -120
- package/node_modules/request/node_modules/qs/index.js +0 -1
- package/node_modules/request/node_modules/qs/lib/index.js +0 -15
- package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
- package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
- package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
- package/node_modules/request/node_modules/qs/package.json +0 -61
- package/node_modules/request/node_modules/qs/test/parse.js +0 -236
- package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
- package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
- package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
- package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
- package/node_modules/request/node_modules/stringstream/README.md +0 -38
- package/node_modules/request/node_modules/stringstream/example.js +0 -27
- package/node_modules/request/node_modules/stringstream/package.json +0 -48
- package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
- package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
- package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
- package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
- package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
- package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
- package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
- package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
- package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
- package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
- package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
- package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
- package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
- package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
- package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
- package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
- package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
- package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
- package/node_modules/request/package.json +0 -77
- package/node_modules/request/request.js +0 -1428
- package/test/fixtures/github-response.json +0 -1367
- package/test/index.js +0 -55
@@ -1,523 +0,0 @@
|
|
1
|
-
// Load modules
|
2
|
-
|
3
|
-
var Boom = require('boom');
|
4
|
-
var Hoek = require('hoek');
|
5
|
-
var Cryptiles = require('cryptiles');
|
6
|
-
var Crypto = require('./crypto');
|
7
|
-
var Utils = require('./utils');
|
8
|
-
|
9
|
-
|
10
|
-
// Declare internals
|
11
|
-
|
12
|
-
var internals = {};
|
13
|
-
|
14
|
-
|
15
|
-
// Hawk authentication
|
16
|
-
|
17
|
-
/*
|
18
|
-
req: node's HTTP request object or an object as follows:
|
19
|
-
|
20
|
-
var request = {
|
21
|
-
method: 'GET',
|
22
|
-
url: '/resource/4?a=1&b=2',
|
23
|
-
host: 'example.com',
|
24
|
-
port: 8080,
|
25
|
-
authorization: 'Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="'
|
26
|
-
};
|
27
|
-
|
28
|
-
credentialsFunc: required function to lookup the set of Hawk credentials based on the provided credentials id.
|
29
|
-
The credentials include the MAC key, MAC algorithm, and other attributes (such as username)
|
30
|
-
needed by the application. This function is the equivalent of verifying the username and
|
31
|
-
password in Basic authentication.
|
32
|
-
|
33
|
-
var credentialsFunc = function (id, callback) {
|
34
|
-
|
35
|
-
// Lookup credentials in database
|
36
|
-
db.lookup(id, function (err, item) {
|
37
|
-
|
38
|
-
if (err || !item) {
|
39
|
-
return callback(err);
|
40
|
-
}
|
41
|
-
|
42
|
-
var credentials = {
|
43
|
-
// Required
|
44
|
-
key: item.key,
|
45
|
-
algorithm: item.algorithm,
|
46
|
-
// Application specific
|
47
|
-
user: item.user
|
48
|
-
};
|
49
|
-
|
50
|
-
return callback(null, credentials);
|
51
|
-
});
|
52
|
-
};
|
53
|
-
|
54
|
-
options: {
|
55
|
-
|
56
|
-
hostHeaderName: optional header field name, used to override the default 'Host' header when used
|
57
|
-
behind a cache of a proxy. Apache2 changes the value of the 'Host' header while preserving
|
58
|
-
the original (which is what the module must verify) in the 'x-forwarded-host' header field.
|
59
|
-
Only used when passed a node Http.ServerRequest object.
|
60
|
-
|
61
|
-
nonceFunc: optional nonce validation function. The function signature is function(nonce, ts, callback)
|
62
|
-
where 'callback' must be called using the signature function(err).
|
63
|
-
|
64
|
-
timestampSkewSec: optional number of seconds of permitted clock skew for incoming timestamps. Defaults to 60 seconds.
|
65
|
-
Provides a +/- skew which means actual allowed window is double the number of seconds.
|
66
|
-
|
67
|
-
localtimeOffsetMsec: optional local clock time offset express in a number of milliseconds (positive or negative).
|
68
|
-
Defaults to 0.
|
69
|
-
|
70
|
-
payload: optional payload for validation. The client calculates the hash value and includes it via the 'hash'
|
71
|
-
header attribute. The server always ensures the value provided has been included in the request
|
72
|
-
MAC. When this option is provided, it validates the hash value itself. Validation is done by calculating
|
73
|
-
a hash value over the entire payload (assuming it has already be normalized to the same format and
|
74
|
-
encoding used by the client to calculate the hash on request). If the payload is not available at the time
|
75
|
-
of authentication, the authenticatePayload() method can be used by passing it the credentials and
|
76
|
-
attributes.hash returned in the authenticate callback.
|
77
|
-
|
78
|
-
host: optional host name override. Only used when passed a node request object.
|
79
|
-
port: optional port override. Only used when passed a node request object.
|
80
|
-
}
|
81
|
-
|
82
|
-
callback: function (err, credentials, artifacts) { }
|
83
|
-
*/
|
84
|
-
|
85
|
-
exports.authenticate = function (req, credentialsFunc, options, callback) {
|
86
|
-
|
87
|
-
callback = Utils.nextTick(callback);
|
88
|
-
|
89
|
-
// Default options
|
90
|
-
|
91
|
-
options.nonceFunc = options.nonceFunc || function (nonce, ts, nonceCallback) { return nonceCallback(); }; // No validation
|
92
|
-
options.timestampSkewSec = options.timestampSkewSec || 60; // 60 seconds
|
93
|
-
|
94
|
-
// Application time
|
95
|
-
|
96
|
-
var now = Utils.now() + (options.localtimeOffsetMsec || 0); // Measure now before any other processing
|
97
|
-
|
98
|
-
// Convert node Http request object to a request configuration object
|
99
|
-
|
100
|
-
var request = Utils.parseRequest(req, options);
|
101
|
-
if (request instanceof Error) {
|
102
|
-
return callback(Boom.badRequest(request.message));
|
103
|
-
}
|
104
|
-
|
105
|
-
// Parse HTTP Authorization header
|
106
|
-
|
107
|
-
var attributes = Utils.parseAuthorizationHeader(request.authorization);
|
108
|
-
if (attributes instanceof Error) {
|
109
|
-
return callback(attributes);
|
110
|
-
}
|
111
|
-
|
112
|
-
// Construct artifacts container
|
113
|
-
|
114
|
-
var artifacts = {
|
115
|
-
method: request.method,
|
116
|
-
host: request.host,
|
117
|
-
port: request.port,
|
118
|
-
resource: request.url,
|
119
|
-
ts: attributes.ts,
|
120
|
-
nonce: attributes.nonce,
|
121
|
-
hash: attributes.hash,
|
122
|
-
ext: attributes.ext,
|
123
|
-
app: attributes.app,
|
124
|
-
dlg: attributes.dlg,
|
125
|
-
mac: attributes.mac,
|
126
|
-
id: attributes.id
|
127
|
-
};
|
128
|
-
|
129
|
-
// Verify required header attributes
|
130
|
-
|
131
|
-
if (!attributes.id ||
|
132
|
-
!attributes.ts ||
|
133
|
-
!attributes.nonce ||
|
134
|
-
!attributes.mac) {
|
135
|
-
|
136
|
-
return callback(Boom.badRequest('Missing attributes'), null, artifacts);
|
137
|
-
}
|
138
|
-
|
139
|
-
// Fetch Hawk credentials
|
140
|
-
|
141
|
-
credentialsFunc(attributes.id, function (err, credentials) {
|
142
|
-
|
143
|
-
if (err) {
|
144
|
-
return callback(err, credentials || null, artifacts);
|
145
|
-
}
|
146
|
-
|
147
|
-
if (!credentials) {
|
148
|
-
return callback(Boom.unauthorized('Unknown credentials', 'Hawk'), null, artifacts);
|
149
|
-
}
|
150
|
-
|
151
|
-
if (!credentials.key ||
|
152
|
-
!credentials.algorithm) {
|
153
|
-
|
154
|
-
return callback(Boom.internal('Invalid credentials'), credentials, artifacts);
|
155
|
-
}
|
156
|
-
|
157
|
-
if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
158
|
-
return callback(Boom.internal('Unknown algorithm'), credentials, artifacts);
|
159
|
-
}
|
160
|
-
|
161
|
-
// Calculate MAC
|
162
|
-
|
163
|
-
var mac = Crypto.calculateMac('header', credentials, artifacts);
|
164
|
-
if (!Cryptiles.fixedTimeComparison(mac, attributes.mac)) {
|
165
|
-
return callback(Boom.unauthorized('Bad mac', 'Hawk'), credentials, artifacts);
|
166
|
-
}
|
167
|
-
|
168
|
-
// Check payload hash
|
169
|
-
|
170
|
-
if (options.payload !== null &&
|
171
|
-
options.payload !== undefined) { // '' is valid
|
172
|
-
|
173
|
-
if (!attributes.hash) {
|
174
|
-
return callback(Boom.unauthorized('Missing required payload hash', 'Hawk'), credentials, artifacts);
|
175
|
-
}
|
176
|
-
|
177
|
-
var hash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, request.contentType);
|
178
|
-
if (!Cryptiles.fixedTimeComparison(hash, attributes.hash)) {
|
179
|
-
return callback(Boom.unauthorized('Bad payload hash', 'Hawk'), credentials, artifacts);
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
// Check nonce
|
184
|
-
|
185
|
-
options.nonceFunc(attributes.nonce, attributes.ts, function (err) {
|
186
|
-
|
187
|
-
if (err) {
|
188
|
-
return callback(Boom.unauthorized('Invalid nonce', 'Hawk'), credentials, artifacts);
|
189
|
-
}
|
190
|
-
|
191
|
-
// Check timestamp staleness
|
192
|
-
|
193
|
-
if (Math.abs((attributes.ts * 1000) - now) > (options.timestampSkewSec * 1000)) {
|
194
|
-
var tsm = Crypto.timestampMessage(credentials, options.localtimeOffsetMsec);
|
195
|
-
return callback(Boom.unauthorized('Stale timestamp', 'Hawk', tsm), credentials, artifacts);
|
196
|
-
}
|
197
|
-
|
198
|
-
// Successful authentication
|
199
|
-
|
200
|
-
return callback(null, credentials, artifacts);
|
201
|
-
});
|
202
|
-
});
|
203
|
-
};
|
204
|
-
|
205
|
-
|
206
|
-
// Authenticate payload hash - used when payload cannot be provided during authenticate()
|
207
|
-
|
208
|
-
/*
|
209
|
-
payload: raw request payload
|
210
|
-
credentials: from authenticate callback
|
211
|
-
artifacts: from authenticate callback
|
212
|
-
contentType: req.headers['content-type']
|
213
|
-
*/
|
214
|
-
|
215
|
-
exports.authenticatePayload = function (payload, credentials, artifacts, contentType) {
|
216
|
-
|
217
|
-
var calculatedHash = Crypto.calculatePayloadHash(payload, credentials.algorithm, contentType);
|
218
|
-
return Cryptiles.fixedTimeComparison(calculatedHash, artifacts.hash);
|
219
|
-
};
|
220
|
-
|
221
|
-
|
222
|
-
// Generate a Server-Authorization header for a given response
|
223
|
-
|
224
|
-
/*
|
225
|
-
credentials: {}, // Object received from authenticate()
|
226
|
-
artifacts: {} // Object received from authenticate(); 'mac', 'hash', and 'ext' - ignored
|
227
|
-
options: {
|
228
|
-
ext: 'application-specific', // Application specific data sent via the ext attribute
|
229
|
-
payload: '{"some":"payload"}', // UTF-8 encoded string for body hash generation (ignored if hash provided)
|
230
|
-
contentType: 'application/json', // Payload content-type (ignored if hash provided)
|
231
|
-
hash: 'U4MKKSmiVxk37JCCrAVIjV=' // Pre-calculated payload hash
|
232
|
-
}
|
233
|
-
*/
|
234
|
-
|
235
|
-
exports.header = function (credentials, artifacts, options) {
|
236
|
-
|
237
|
-
// Prepare inputs
|
238
|
-
|
239
|
-
options = options || {};
|
240
|
-
|
241
|
-
if (!artifacts ||
|
242
|
-
typeof artifacts !== 'object' ||
|
243
|
-
typeof options !== 'object') {
|
244
|
-
|
245
|
-
return '';
|
246
|
-
}
|
247
|
-
|
248
|
-
artifacts = Hoek.clone(artifacts);
|
249
|
-
delete artifacts.mac;
|
250
|
-
artifacts.hash = options.hash;
|
251
|
-
artifacts.ext = options.ext;
|
252
|
-
|
253
|
-
// Validate credentials
|
254
|
-
|
255
|
-
if (!credentials ||
|
256
|
-
!credentials.key ||
|
257
|
-
!credentials.algorithm) {
|
258
|
-
|
259
|
-
// Invalid credential object
|
260
|
-
return '';
|
261
|
-
}
|
262
|
-
|
263
|
-
if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
264
|
-
return '';
|
265
|
-
}
|
266
|
-
|
267
|
-
// Calculate payload hash
|
268
|
-
|
269
|
-
if (!artifacts.hash &&
|
270
|
-
options.hasOwnProperty('payload')) {
|
271
|
-
|
272
|
-
artifacts.hash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
|
273
|
-
}
|
274
|
-
|
275
|
-
var mac = Crypto.calculateMac('response', credentials, artifacts);
|
276
|
-
|
277
|
-
// Construct header
|
278
|
-
|
279
|
-
var header = 'Hawk mac="' + mac + '"' +
|
280
|
-
(artifacts.hash ? ', hash="' + artifacts.hash + '"' : '');
|
281
|
-
|
282
|
-
if (artifacts.ext !== null &&
|
283
|
-
artifacts.ext !== undefined &&
|
284
|
-
artifacts.ext !== '') { // Other falsey values allowed
|
285
|
-
|
286
|
-
header += ', ext="' + Utils.escapeHeaderAttribute(artifacts.ext) + '"';
|
287
|
-
}
|
288
|
-
|
289
|
-
return header;
|
290
|
-
};
|
291
|
-
|
292
|
-
|
293
|
-
/*
|
294
|
-
* Arguments and options are the same as authenticate() with the exception that the only supported options are:
|
295
|
-
* 'hostHeaderName', 'localtimeOffsetMsec', 'host', 'port'
|
296
|
-
*/
|
297
|
-
|
298
|
-
exports.authenticateBewit = function (req, credentialsFunc, options, callback) {
|
299
|
-
|
300
|
-
callback = Utils.nextTick(callback);
|
301
|
-
|
302
|
-
// Application time
|
303
|
-
|
304
|
-
var now = Utils.now() + (options.localtimeOffsetMsec || 0);
|
305
|
-
|
306
|
-
// Convert node Http request object to a request configuration object
|
307
|
-
|
308
|
-
var request = Utils.parseRequest(req, options);
|
309
|
-
if (request instanceof Error) {
|
310
|
-
return callback(Boom.badRequest(request.message));
|
311
|
-
}
|
312
|
-
|
313
|
-
// Extract bewit
|
314
|
-
|
315
|
-
// 1 2 3 4
|
316
|
-
var resource = request.url.match(/^(\/.*)([\?&])bewit\=([^&$]*)(?:&(.+))?$/);
|
317
|
-
if (!resource) {
|
318
|
-
return callback(Boom.unauthorized(null, 'Hawk'));
|
319
|
-
}
|
320
|
-
|
321
|
-
// Bewit not empty
|
322
|
-
|
323
|
-
if (!resource[3]) {
|
324
|
-
return callback(Boom.unauthorized('Empty bewit', 'Hawk'));
|
325
|
-
}
|
326
|
-
|
327
|
-
// Verify method is GET
|
328
|
-
|
329
|
-
if (request.method !== 'GET' &&
|
330
|
-
request.method !== 'HEAD') {
|
331
|
-
|
332
|
-
return callback(Boom.unauthorized('Invalid method', 'Hawk'));
|
333
|
-
}
|
334
|
-
|
335
|
-
// No other authentication
|
336
|
-
|
337
|
-
if (request.authorization) {
|
338
|
-
return callback(Boom.badRequest('Multiple authentications', 'Hawk'));
|
339
|
-
}
|
340
|
-
|
341
|
-
// Parse bewit
|
342
|
-
|
343
|
-
var bewitString = Utils.base64urlDecode(resource[3]);
|
344
|
-
if (bewitString instanceof Error) {
|
345
|
-
return callback(Boom.badRequest('Invalid bewit encoding'));
|
346
|
-
}
|
347
|
-
|
348
|
-
// Bewit format: id\exp\mac\ext ('\' is used because it is a reserved header attribute character)
|
349
|
-
|
350
|
-
var bewitParts = bewitString.split('\\');
|
351
|
-
if (!bewitParts ||
|
352
|
-
bewitParts.length !== 4) {
|
353
|
-
|
354
|
-
return callback(Boom.badRequest('Invalid bewit structure'));
|
355
|
-
}
|
356
|
-
|
357
|
-
var bewit = {
|
358
|
-
id: bewitParts[0],
|
359
|
-
exp: parseInt(bewitParts[1], 10),
|
360
|
-
mac: bewitParts[2],
|
361
|
-
ext: bewitParts[3] || ''
|
362
|
-
};
|
363
|
-
|
364
|
-
if (!bewit.id ||
|
365
|
-
!bewit.exp ||
|
366
|
-
!bewit.mac) {
|
367
|
-
|
368
|
-
return callback(Boom.badRequest('Missing bewit attributes'));
|
369
|
-
}
|
370
|
-
|
371
|
-
// Construct URL without bewit
|
372
|
-
|
373
|
-
var url = resource[1];
|
374
|
-
if (resource[4]) {
|
375
|
-
url += resource[2] + resource[4];
|
376
|
-
}
|
377
|
-
|
378
|
-
// Check expiration
|
379
|
-
|
380
|
-
if (bewit.exp * 1000 <= now) {
|
381
|
-
return callback(Boom.unauthorized('Access expired', 'Hawk'), null, bewit);
|
382
|
-
}
|
383
|
-
|
384
|
-
// Fetch Hawk credentials
|
385
|
-
|
386
|
-
credentialsFunc(bewit.id, function (err, credentials) {
|
387
|
-
|
388
|
-
if (err) {
|
389
|
-
return callback(err, credentials || null, bewit.ext);
|
390
|
-
}
|
391
|
-
|
392
|
-
if (!credentials) {
|
393
|
-
return callback(Boom.unauthorized('Unknown credentials', 'Hawk'), null, bewit);
|
394
|
-
}
|
395
|
-
|
396
|
-
if (!credentials.key ||
|
397
|
-
!credentials.algorithm) {
|
398
|
-
|
399
|
-
return callback(Boom.internal('Invalid credentials'), credentials, bewit);
|
400
|
-
}
|
401
|
-
|
402
|
-
if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
403
|
-
return callback(Boom.internal('Unknown algorithm'), credentials, bewit);
|
404
|
-
}
|
405
|
-
|
406
|
-
// Calculate MAC
|
407
|
-
|
408
|
-
var mac = Crypto.calculateMac('bewit', credentials, {
|
409
|
-
ts: bewit.exp,
|
410
|
-
nonce: '',
|
411
|
-
method: 'GET',
|
412
|
-
resource: url,
|
413
|
-
host: request.host,
|
414
|
-
port: request.port,
|
415
|
-
ext: bewit.ext
|
416
|
-
});
|
417
|
-
|
418
|
-
if (!Cryptiles.fixedTimeComparison(mac, bewit.mac)) {
|
419
|
-
return callback(Boom.unauthorized('Bad mac', 'Hawk'), credentials, bewit);
|
420
|
-
}
|
421
|
-
|
422
|
-
// Successful authentication
|
423
|
-
|
424
|
-
return callback(null, credentials, bewit);
|
425
|
-
});
|
426
|
-
};
|
427
|
-
|
428
|
-
|
429
|
-
/*
|
430
|
-
* options are the same as authenticate() with the exception that the only supported options are:
|
431
|
-
* 'nonceFunc', 'timestampSkewSec', 'localtimeOffsetMsec'
|
432
|
-
*/
|
433
|
-
|
434
|
-
exports.authenticateMessage = function (host, port, message, authorization, credentialsFunc, options, callback) {
|
435
|
-
|
436
|
-
callback = Utils.nextTick(callback);
|
437
|
-
|
438
|
-
// Default options
|
439
|
-
|
440
|
-
options.nonceFunc = options.nonceFunc || function (nonce, ts, nonceCallback) { return nonceCallback(); }; // No validation
|
441
|
-
options.timestampSkewSec = options.timestampSkewSec || 60; // 60 seconds
|
442
|
-
|
443
|
-
// Application time
|
444
|
-
|
445
|
-
var now = Utils.now() + (options.localtimeOffsetMsec || 0); // Measure now before any other processing
|
446
|
-
|
447
|
-
// Validate authorization
|
448
|
-
|
449
|
-
if (!authorization.id ||
|
450
|
-
!authorization.ts ||
|
451
|
-
!authorization.nonce ||
|
452
|
-
!authorization.hash ||
|
453
|
-
!authorization.mac) {
|
454
|
-
|
455
|
-
return callback(Boom.badRequest('Invalid authorization'))
|
456
|
-
}
|
457
|
-
|
458
|
-
// Fetch Hawk credentials
|
459
|
-
|
460
|
-
credentialsFunc(authorization.id, function (err, credentials) {
|
461
|
-
|
462
|
-
if (err) {
|
463
|
-
return callback(err, credentials || null);
|
464
|
-
}
|
465
|
-
|
466
|
-
if (!credentials) {
|
467
|
-
return callback(Boom.unauthorized('Unknown credentials', 'Hawk'));
|
468
|
-
}
|
469
|
-
|
470
|
-
if (!credentials.key ||
|
471
|
-
!credentials.algorithm) {
|
472
|
-
|
473
|
-
return callback(Boom.internal('Invalid credentials'), credentials);
|
474
|
-
}
|
475
|
-
|
476
|
-
if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
|
477
|
-
return callback(Boom.internal('Unknown algorithm'), credentials);
|
478
|
-
}
|
479
|
-
|
480
|
-
// Construct artifacts container
|
481
|
-
|
482
|
-
var artifacts = {
|
483
|
-
ts: authorization.ts,
|
484
|
-
nonce: authorization.nonce,
|
485
|
-
host: host,
|
486
|
-
port: port,
|
487
|
-
hash: authorization.hash
|
488
|
-
};
|
489
|
-
|
490
|
-
// Calculate MAC
|
491
|
-
|
492
|
-
var mac = Crypto.calculateMac('message', credentials, artifacts);
|
493
|
-
if (!Cryptiles.fixedTimeComparison(mac, authorization.mac)) {
|
494
|
-
return callback(Boom.unauthorized('Bad mac', 'Hawk'), credentials);
|
495
|
-
}
|
496
|
-
|
497
|
-
// Check payload hash
|
498
|
-
|
499
|
-
var hash = Crypto.calculatePayloadHash(message, credentials.algorithm);
|
500
|
-
if (!Cryptiles.fixedTimeComparison(hash, authorization.hash)) {
|
501
|
-
return callback(Boom.unauthorized('Bad message hash', 'Hawk'), credentials);
|
502
|
-
}
|
503
|
-
|
504
|
-
// Check nonce
|
505
|
-
|
506
|
-
options.nonceFunc(authorization.nonce, authorization.ts, function (err) {
|
507
|
-
|
508
|
-
if (err) {
|
509
|
-
return callback(Boom.unauthorized('Invalid nonce', 'Hawk'), credentials);
|
510
|
-
}
|
511
|
-
|
512
|
-
// Check timestamp staleness
|
513
|
-
|
514
|
-
if (Math.abs((authorization.ts * 1000) - now) > (options.timestampSkewSec * 1000)) {
|
515
|
-
return callback(Boom.unauthorized('Stale timestamp'), credentials);
|
516
|
-
}
|
517
|
-
|
518
|
-
// Successful authentication
|
519
|
-
|
520
|
-
return callback(null, credentials);
|
521
|
-
});
|
522
|
-
});
|
523
|
-
};
|
@@ -1,183 +0,0 @@
|
|
1
|
-
// Load modules
|
2
|
-
|
3
|
-
var Hoek = require('hoek');
|
4
|
-
var Sntp = require('sntp');
|
5
|
-
var Boom = require('boom');
|
6
|
-
|
7
|
-
|
8
|
-
// Declare internals
|
9
|
-
|
10
|
-
var internals = {};
|
11
|
-
|
12
|
-
|
13
|
-
// Import Hoek Utilities
|
14
|
-
|
15
|
-
internals.import = function () {
|
16
|
-
|
17
|
-
for (var i in Hoek) {
|
18
|
-
if (Hoek.hasOwnProperty(i)) {
|
19
|
-
exports[i] = Hoek[i];
|
20
|
-
}
|
21
|
-
}
|
22
|
-
};
|
23
|
-
|
24
|
-
internals.import();
|
25
|
-
|
26
|
-
|
27
|
-
// Hawk version
|
28
|
-
|
29
|
-
exports.version = function () {
|
30
|
-
|
31
|
-
return exports.loadPackage(__dirname + '/..').version;
|
32
|
-
};
|
33
|
-
|
34
|
-
|
35
|
-
// Extract host and port from request
|
36
|
-
|
37
|
-
exports.parseHost = function (req, hostHeaderName) {
|
38
|
-
|
39
|
-
hostHeaderName = (hostHeaderName ? hostHeaderName.toLowerCase() : 'host');
|
40
|
-
var hostHeader = req.headers[hostHeaderName];
|
41
|
-
if (!hostHeader) {
|
42
|
-
return null;
|
43
|
-
}
|
44
|
-
|
45
|
-
var hostHeaderRegex;
|
46
|
-
if (hostHeader[0] === '[') {
|
47
|
-
hostHeaderRegex = /^(?:(?:\r\n)?\s)*(\[[^\]]+\])(?::(\d+))?(?:(?:\r\n)?\s)*$/; // IPv6
|
48
|
-
}
|
49
|
-
else {
|
50
|
-
hostHeaderRegex = /^(?:(?:\r\n)?\s)*([^:]+)(?::(\d+))?(?:(?:\r\n)?\s)*$/; // IPv4, hostname
|
51
|
-
}
|
52
|
-
|
53
|
-
var hostParts = hostHeader.match(hostHeaderRegex);
|
54
|
-
|
55
|
-
if (!hostParts ||
|
56
|
-
hostParts.length !== 3 ||
|
57
|
-
!hostParts[1]) {
|
58
|
-
|
59
|
-
return null;
|
60
|
-
}
|
61
|
-
|
62
|
-
return {
|
63
|
-
name: hostParts[1],
|
64
|
-
port: (hostParts[2] ? hostParts[2] : (req.connection && req.connection.encrypted ? 443 : 80))
|
65
|
-
};
|
66
|
-
};
|
67
|
-
|
68
|
-
|
69
|
-
// Parse Content-Type header content
|
70
|
-
|
71
|
-
exports.parseContentType = function (header) {
|
72
|
-
|
73
|
-
if (!header) {
|
74
|
-
return '';
|
75
|
-
}
|
76
|
-
|
77
|
-
return header.split(';')[0].trim().toLowerCase();
|
78
|
-
};
|
79
|
-
|
80
|
-
|
81
|
-
// Convert node's to request configuration object
|
82
|
-
|
83
|
-
exports.parseRequest = function (req, options) {
|
84
|
-
|
85
|
-
if (!req.headers) {
|
86
|
-
return req;
|
87
|
-
}
|
88
|
-
|
89
|
-
// Obtain host and port information
|
90
|
-
|
91
|
-
if (!options.host || !options.port) {
|
92
|
-
var host = exports.parseHost(req, options.hostHeaderName);
|
93
|
-
if (!host) {
|
94
|
-
return new Error('Invalid Host header');
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
var request = {
|
99
|
-
method: req.method,
|
100
|
-
url: req.url,
|
101
|
-
host: options.host || host.name,
|
102
|
-
port: options.port || host.port,
|
103
|
-
authorization: req.headers.authorization,
|
104
|
-
contentType: req.headers['content-type'] || ''
|
105
|
-
};
|
106
|
-
|
107
|
-
return request;
|
108
|
-
};
|
109
|
-
|
110
|
-
|
111
|
-
exports.now = function () {
|
112
|
-
|
113
|
-
return Sntp.now();
|
114
|
-
};
|
115
|
-
|
116
|
-
|
117
|
-
// Parse Hawk HTTP Authorization header
|
118
|
-
|
119
|
-
exports.parseAuthorizationHeader = function (header, keys) {
|
120
|
-
|
121
|
-
keys = keys || ['id', 'ts', 'nonce', 'hash', 'ext', 'mac', 'app', 'dlg'];
|
122
|
-
|
123
|
-
if (!header) {
|
124
|
-
return Boom.unauthorized(null, 'Hawk');
|
125
|
-
}
|
126
|
-
|
127
|
-
var headerParts = header.match(/^(\w+)(?:\s+(.*))?$/); // Header: scheme[ something]
|
128
|
-
if (!headerParts) {
|
129
|
-
return Boom.badRequest('Invalid header syntax');
|
130
|
-
}
|
131
|
-
|
132
|
-
var scheme = headerParts[1];
|
133
|
-
if (scheme.toLowerCase() !== 'hawk') {
|
134
|
-
return Boom.unauthorized(null, 'Hawk');
|
135
|
-
}
|
136
|
-
|
137
|
-
var attributesString = headerParts[2];
|
138
|
-
if (!attributesString) {
|
139
|
-
return Boom.badRequest('Invalid header syntax');
|
140
|
-
}
|
141
|
-
|
142
|
-
var attributes = {};
|
143
|
-
var errorMessage = '';
|
144
|
-
var verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, function ($0, $1, $2) {
|
145
|
-
|
146
|
-
// Check valid attribute names
|
147
|
-
|
148
|
-
if (keys.indexOf($1) === -1) {
|
149
|
-
errorMessage = 'Unknown attribute: ' + $1;
|
150
|
-
return;
|
151
|
-
}
|
152
|
-
|
153
|
-
// Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
|
154
|
-
|
155
|
-
if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
|
156
|
-
errorMessage = 'Bad attribute value: ' + $1;
|
157
|
-
return;
|
158
|
-
}
|
159
|
-
|
160
|
-
// Check for duplicates
|
161
|
-
|
162
|
-
if (attributes.hasOwnProperty($1)) {
|
163
|
-
errorMessage = 'Duplicate attribute: ' + $1;
|
164
|
-
return;
|
165
|
-
}
|
166
|
-
|
167
|
-
attributes[$1] = $2;
|
168
|
-
return '';
|
169
|
-
});
|
170
|
-
|
171
|
-
if (verify !== '') {
|
172
|
-
return Boom.badRequest(errorMessage || 'Bad header format');
|
173
|
-
}
|
174
|
-
|
175
|
-
return attributes;
|
176
|
-
};
|
177
|
-
|
178
|
-
|
179
|
-
exports.unauthorized = function (message) {
|
180
|
-
|
181
|
-
return Boom.unauthorized(message, 'Hawk');
|
182
|
-
};
|
183
|
-
|