@udibo/oauth2 0.1.0
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 +20 -0
- package/README.md +174 -0
- package/SECURITY.md +77 -0
- package/esm/_dnt.polyfills.d.ts +17 -0
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/adapters/hono/_common.d.ts +66 -0
- package/esm/adapters/hono/_common.js +108 -0
- package/esm/adapters/hono/authorization-server.d.ts +211 -0
- package/esm/adapters/hono/authorization-server.js +214 -0
- package/esm/adapters/hono/bff/auth-request-store.d.ts +164 -0
- package/esm/adapters/hono/bff/auth-request-store.js +154 -0
- package/esm/adapters/hono/bff/bff.d.ts +852 -0
- package/esm/adapters/hono/bff/bff.js +1194 -0
- package/esm/adapters/hono/bff/cookie-prefix.d.ts +72 -0
- package/esm/adapters/hono/bff/cookie-prefix.js +85 -0
- package/esm/adapters/hono/bff/mod.d.ts +19 -0
- package/esm/adapters/hono/bff/mod.js +19 -0
- package/esm/adapters/hono/bff/proxy.d.ts +108 -0
- package/esm/adapters/hono/bff/proxy.js +314 -0
- package/esm/adapters/hono/bff/session-store.d.ts +250 -0
- package/esm/adapters/hono/bff/session-store.js +216 -0
- package/esm/adapters/hono/bff/testing.d.ts +165 -0
- package/esm/adapters/hono/bff/testing.js +254 -0
- package/esm/adapters/hono/identity.d.ts +117 -0
- package/esm/adapters/hono/identity.js +215 -0
- package/esm/adapters/hono/log.d.ts +49 -0
- package/esm/adapters/hono/log.js +66 -0
- package/esm/adapters/hono/resource-server.d.ts +101 -0
- package/esm/adapters/hono/resource-server.js +108 -0
- package/esm/client/_http.d.ts +91 -0
- package/esm/client/_http.js +303 -0
- package/esm/client/base.d.ts +184 -0
- package/esm/client/base.js +93 -0
- package/esm/client/bff-client.d.ts +235 -0
- package/esm/client/bff-client.js +280 -0
- package/esm/client/browser-storage.d.ts +152 -0
- package/esm/client/browser-storage.js +246 -0
- package/esm/client/check.d.ts +114 -0
- package/esm/client/check.js +97 -0
- package/esm/client/direct-client.d.ts +707 -0
- package/esm/client/direct-client.js +1237 -0
- package/esm/client/discovery-cache.d.ts +138 -0
- package/esm/client/discovery-cache.js +124 -0
- package/esm/client/events.d.ts +54 -0
- package/esm/client/events.js +37 -0
- package/esm/client/mod.d.ts +35 -0
- package/esm/client/mod.js +33 -0
- package/esm/client/storage.d.ts +127 -0
- package/esm/client/storage.js +81 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +16 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +193 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +36 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +14 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +43 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +41 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +14 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +14 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
- package/esm/deps/jsr.io/@std/async/1.5.0/delay.d.ts +44 -0
- package/esm/deps/jsr.io/@std/async/1.5.0/delay.js +84 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +39 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +61 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.d.ts +22 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.js +51 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.d.ts +34 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.js +192 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.d.ts +34 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.js +113 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.d.ts +3 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.js +13 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.d.ts +8 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.js +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.d.ts +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.js +26 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.d.ts +60 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.js +152 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.d.ts +39 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.js +87 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.d.ts +39 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.js +131 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.d.ts +39 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.js +82 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.d.ts +39 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.js +72 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.d.ts +38 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.js +87 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.d.ts +97 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.js +99 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.d.ts +119 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.js +209 -0
- package/esm/deps/jsr.io/@std/http/1.1.3/status.d.ts +343 -0
- package/esm/deps/jsr.io/@std/http/1.1.3/status.js +343 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.d.ts +159 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.js +223 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.d.ts +79 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.js +116 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/diff.d.ts +139 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/diff.js +277 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.d.ts +98 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.js +181 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/format.d.ts +29 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/format.js +68 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/styles.d.ts +158 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/styles.js +206 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/types.d.ts +24 -0
- package/esm/deps/jsr.io/@std/internal/1.0.14/types.js +3 -0
- package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.d.ts +91 -0
- package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.js +347 -0
- package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.d.ts +382 -0
- package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.js +1110 -0
- package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.d.ts +363 -0
- package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.js +616 -0
- package/esm/errors.d.ts +203 -0
- package/esm/errors.js +287 -0
- package/esm/identity/captcha.d.ts +147 -0
- package/esm/identity/captcha.js +64 -0
- package/esm/identity/delivery.d.ts +96 -0
- package/esm/identity/delivery.js +41 -0
- package/esm/identity/errors.d.ts +39 -0
- package/esm/identity/errors.js +46 -0
- package/esm/identity/events.d.ts +242 -0
- package/esm/identity/events.js +39 -0
- package/esm/identity/external/_shared.d.ts +86 -0
- package/esm/identity/external/_shared.js +107 -0
- package/esm/identity/external/_token-exchange.d.ts +61 -0
- package/esm/identity/external/_token-exchange.js +179 -0
- package/esm/identity/external/apple-client-secret.d.ts +82 -0
- package/esm/identity/external/apple-client-secret.js +133 -0
- package/esm/identity/external/apple.d.ts +64 -0
- package/esm/identity/external/apple.js +248 -0
- package/esm/identity/external/discord.d.ts +38 -0
- package/esm/identity/external/discord.js +62 -0
- package/esm/identity/external/errors.d.ts +48 -0
- package/esm/identity/external/errors.js +36 -0
- package/esm/identity/external/flow.d.ts +107 -0
- package/esm/identity/external/flow.js +158 -0
- package/esm/identity/external/github.d.ts +42 -0
- package/esm/identity/external/github.js +164 -0
- package/esm/identity/external/google.d.ts +52 -0
- package/esm/identity/external/google.js +38 -0
- package/esm/identity/external/mod.d.ts +63 -0
- package/esm/identity/external/mod.js +61 -0
- package/esm/identity/external/oauth2.d.ts +110 -0
- package/esm/identity/external/oauth2.js +158 -0
- package/esm/identity/external/oidc.d.ts +81 -0
- package/esm/identity/external/oidc.js +250 -0
- package/esm/identity/external/provider.d.ts +132 -0
- package/esm/identity/external/provider.js +12 -0
- package/esm/identity/hibp.d.ts +67 -0
- package/esm/identity/hibp.js +87 -0
- package/esm/identity/identifier.d.ts +44 -0
- package/esm/identity/identifier.js +47 -0
- package/esm/identity/lockout.d.ts +155 -0
- package/esm/identity/lockout.js +117 -0
- package/esm/identity/mfa/mod.d.ts +42 -0
- package/esm/identity/mfa/mod.js +42 -0
- package/esm/identity/mfa/recovery-codes.d.ts +96 -0
- package/esm/identity/mfa/recovery-codes.js +80 -0
- package/esm/identity/mfa/service.d.ts +338 -0
- package/esm/identity/mfa/service.js +351 -0
- package/esm/identity/mfa/totp.d.ts +186 -0
- package/esm/identity/mfa/totp.js +194 -0
- package/esm/identity/migration.d.ts +155 -0
- package/esm/identity/migration.js +243 -0
- package/esm/identity/mod.d.ts +65 -0
- package/esm/identity/mod.js +64 -0
- package/esm/identity/otp.d.ts +255 -0
- package/esm/identity/otp.js +245 -0
- package/esm/identity/password-policy.d.ts +45 -0
- package/esm/identity/password-policy.js +60 -0
- package/esm/identity/password.d.ts +171 -0
- package/esm/identity/password.js +160 -0
- package/esm/identity/rate-limit.d.ts +192 -0
- package/esm/identity/rate-limit.js +168 -0
- package/esm/identity/service.d.ts +579 -0
- package/esm/identity/service.js +835 -0
- package/esm/identity/session.d.ts +122 -0
- package/esm/identity/session.js +48 -0
- package/esm/identity/token-flow.d.ts +214 -0
- package/esm/identity/token-flow.js +173 -0
- package/esm/models/authentication.d.ts +24 -0
- package/esm/models/authentication.js +1 -0
- package/esm/models/authorization-code.d.ts +63 -0
- package/esm/models/authorization-code.js +1 -0
- package/esm/models/authorization.d.ts +165 -0
- package/esm/models/authorization.js +160 -0
- package/esm/models/client.d.ts +78 -0
- package/esm/models/client.js +1 -0
- package/esm/models/device-authorization.d.ts +30 -0
- package/esm/models/device-authorization.js +1 -0
- package/esm/models/responses.d.ts +93 -0
- package/esm/models/responses.js +1 -0
- package/esm/models/scope.d.ts +81 -0
- package/esm/models/scope.js +125 -0
- package/esm/models/token.d.ts +135 -0
- package/esm/models/token.js +1 -0
- package/esm/package.json +3 -0
- package/esm/react/callback.d.ts +52 -0
- package/esm/react/callback.js +71 -0
- package/esm/react/components/class-names.d.ts +91 -0
- package/esm/react/components/class-names.js +118 -0
- package/esm/react/components/internal.d.ts +62 -0
- package/esm/react/components/internal.js +102 -0
- package/esm/react/components/mfa-challenge-form.d.ts +66 -0
- package/esm/react/components/mfa-challenge-form.js +46 -0
- package/esm/react/components/mfa-enrollment-form.d.ts +83 -0
- package/esm/react/components/mfa-enrollment-form.js +41 -0
- package/esm/react/components/mod.d.ts +103 -0
- package/esm/react/components/mod.js +93 -0
- package/esm/react/components/request-password-reset-form.d.ts +61 -0
- package/esm/react/components/request-password-reset-form.js +41 -0
- package/esm/react/components/reset-password-form.d.ts +66 -0
- package/esm/react/components/reset-password-form.js +56 -0
- package/esm/react/components/sign-in-form.d.ts +74 -0
- package/esm/react/components/sign-in-form.js +43 -0
- package/esm/react/components/sign-up-form.d.ts +85 -0
- package/esm/react/components/sign-up-form.js +57 -0
- package/esm/react/components/types.d.ts +208 -0
- package/esm/react/components/types.js +14 -0
- package/esm/react/components/use-auth-form.d.ts +118 -0
- package/esm/react/components/use-auth-form.js +172 -0
- package/esm/react/components/user-menu.d.ts +79 -0
- package/esm/react/components/user-menu.js +73 -0
- package/esm/react/context.d.ts +51 -0
- package/esm/react/context.js +16 -0
- package/esm/react/mod.d.ts +26 -0
- package/esm/react/mod.js +26 -0
- package/esm/react/provider.d.ts +40 -0
- package/esm/react/provider.js +189 -0
- package/esm/react/require-auth.d.ts +31 -0
- package/esm/react/require-auth.js +37 -0
- package/esm/react/testing.d.ts +322 -0
- package/esm/react/testing.js +461 -0
- package/esm/react/use-authorization.d.ts +31 -0
- package/esm/react/use-authorization.js +36 -0
- package/esm/react/use-oauth2.d.ts +112 -0
- package/esm/react/use-oauth2.js +127 -0
- package/esm/server/authorization-server.d.ts +736 -0
- package/esm/server/authorization-server.js +1304 -0
- package/esm/server/client-authentication.d.ts +28 -0
- package/esm/server/client-authentication.js +51 -0
- package/esm/server/grants/authorization-code.d.ts +179 -0
- package/esm/server/grants/authorization-code.js +232 -0
- package/esm/server/grants/client-credentials.d.ts +52 -0
- package/esm/server/grants/client-credentials.js +53 -0
- package/esm/server/grants/device-authorization.d.ts +103 -0
- package/esm/server/grants/device-authorization.js +156 -0
- package/esm/server/grants/grant.d.ts +165 -0
- package/esm/server/grants/grant.js +173 -0
- package/esm/server/grants/password.d.ts +80 -0
- package/esm/server/grants/password.js +92 -0
- package/esm/server/grants/refresh-token.d.ts +80 -0
- package/esm/server/grants/refresh-token.js +136 -0
- package/esm/server/introspection-token-reader.d.ts +153 -0
- package/esm/server/introspection-token-reader.js +164 -0
- package/esm/server/jwks-token-reader.d.ts +263 -0
- package/esm/server/jwks-token-reader.js +508 -0
- package/esm/server/mod.d.ts +23 -0
- package/esm/server/mod.js +15 -0
- package/esm/server/public-suffix/mod.d.ts +62 -0
- package/esm/server/public-suffix/mod.js +103 -0
- package/esm/server/public-suffix/rules.d.ts +23 -0
- package/esm/server/public-suffix/rules.js +23 -0
- package/esm/server/redirect-uri.d.ts +187 -0
- package/esm/server/redirect-uri.js +331 -0
- package/esm/server/resource-server.d.ts +286 -0
- package/esm/server/resource-server.js +365 -0
- package/esm/server/services/authorization-code.d.ts +84 -0
- package/esm/server/services/authorization-code.js +35 -0
- package/esm/server/services/client.d.ts +35 -0
- package/esm/server/services/client.js +1 -0
- package/esm/server/services/device-authorization.d.ts +134 -0
- package/esm/server/services/device-authorization.js +7 -0
- package/esm/server/services/token.d.ts +242 -0
- package/esm/server/services/token.js +78 -0
- package/esm/server/services/user.d.ts +29 -0
- package/esm/server/services/user.js +7 -0
- package/esm/server/signing-keys.d.ts +201 -0
- package/esm/server/signing-keys.js +225 -0
- package/esm/server/utils/hash.d.ts +6 -0
- package/esm/server/utils/hash.js +11 -0
- package/esm/testing/contract/authorization-code.d.ts +37 -0
- package/esm/testing/contract/authorization-code.js +93 -0
- package/esm/testing/contract/client.d.ts +85 -0
- package/esm/testing/contract/client.js +126 -0
- package/esm/testing/contract/device-authorization.d.ts +37 -0
- package/esm/testing/contract/device-authorization.js +193 -0
- package/esm/testing/contract/lockout-store.d.ts +47 -0
- package/esm/testing/contract/lockout-store.js +122 -0
- package/esm/testing/contract/mfa-store.d.ts +50 -0
- package/esm/testing/contract/mfa-store.js +226 -0
- package/esm/testing/contract/mod.d.ts +39 -0
- package/esm/testing/contract/mod.js +39 -0
- package/esm/testing/contract/otp-store.d.ts +48 -0
- package/esm/testing/contract/otp-store.js +197 -0
- package/esm/testing/contract/rate-limit-store.d.ts +52 -0
- package/esm/testing/contract/rate-limit-store.js +105 -0
- package/esm/testing/contract/token-flow-store.d.ts +54 -0
- package/esm/testing/contract/token-flow-store.js +179 -0
- package/esm/testing/contract/token-reader.d.ts +77 -0
- package/esm/testing/contract/token-reader.js +78 -0
- package/esm/testing/contract/token.d.ts +61 -0
- package/esm/testing/contract/token.js +287 -0
- package/esm/testing/contract/user.d.ts +63 -0
- package/esm/testing/contract/user.js +75 -0
- package/esm/testing/mod.d.ts +34 -0
- package/esm/testing/mod.js +34 -0
- package/esm/testing/server.d.ts +197 -0
- package/esm/testing/server.js +193 -0
- package/esm/testing/services.d.ts +373 -0
- package/esm/testing/services.js +703 -0
- package/esm/utils/_buffer.d.ts +10 -0
- package/esm/utils/_buffer.js +12 -0
- package/esm/utils/_timing-safe.d.ts +13 -0
- package/esm/utils/_timing-safe.js +22 -0
- package/esm/utils/authentication-context.d.ts +3 -0
- package/esm/utils/authentication-context.js +14 -0
- package/esm/utils/basic-auth.d.ts +50 -0
- package/esm/utils/basic-auth.js +106 -0
- package/esm/utils/crypto.d.ts +97 -0
- package/esm/utils/crypto.js +162 -0
- package/esm/utils/pkce.d.ts +151 -0
- package/esm/utils/pkce.js +179 -0
- package/esm/utils/text.d.ts +24 -0
- package/esm/utils/text.js +28 -0
- package/esm/utils/url.d.ts +66 -0
- package/esm/utils/url.js +90 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Udibo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @udibo/oauth2
|
|
2
|
+
|
|
3
|
+
OAuth2 and OpenID Connect tools for TypeScript applications. Connect your app to
|
|
4
|
+
Udibo's identity service, or host an authorization server for your own app. The
|
|
5
|
+
package includes clients, authorization and resource servers, Hono middleware,
|
|
6
|
+
React bindings, and optional login flows over your own database.
|
|
7
|
+
|
|
8
|
+
**Udibo's managed identity service is in private beta.**
|
|
9
|
+
[Join the waitlist](https://udibo.com). The self-hosted examples run locally
|
|
10
|
+
without a hosted account.
|
|
11
|
+
|
|
12
|
+
## Choose your path
|
|
13
|
+
|
|
14
|
+
| Your application needs | Start here |
|
|
15
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
16
|
+
| Udibo to handle sign-in | [Use Udibo's identity service](docs/guides/use-udibo.md) — private-beta access required |
|
|
17
|
+
| Its own login and authorization server | [Run the quickstart](docs/quickstart.md), then [host authorization for your app](docs/guides/become-an-oauth-provider.md) |
|
|
18
|
+
| An API that accepts access tokens | [Protect an API](docs/guides/protect-an-api.md) |
|
|
19
|
+
| A React application with server-held tokens | [Juniper starter](templates/juniper/README.md) or [React Router starter](templates/react-router/README.md) |
|
|
20
|
+
|
|
21
|
+
[Documentation index](docs/index.md) ·
|
|
22
|
+
[API reference](https://jsr.io/@udibo/oauth2/doc) · [Examples](#examples) ·
|
|
23
|
+
[Agent documentation](#for-coding-agents)
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
Requires Deno 2 for the development workflow:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
deno add jsr:@udibo/oauth2@0.1.0
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Import the part you use; there is no root barrel or default export:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { BffClient, DirectClient } from "@udibo/oauth2/client";
|
|
37
|
+
import { HonoBff } from "@udibo/oauth2/hono/bff";
|
|
38
|
+
import { HonoResourceServer } from "@udibo/oauth2/hono/resource-server";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Version `0.1.0` is a pre-1.0 API. Minor releases may contain breaking changes;
|
|
42
|
+
review the [stability policy](docs/stability.md) before upgrading.
|
|
43
|
+
|
|
44
|
+
## How the pieces fit
|
|
45
|
+
|
|
46
|
+
For a browser app, use a backend-for-frontend (BFF). The browser holds an
|
|
47
|
+
HttpOnly session cookie; the BFF exchanges authorization codes and keeps access
|
|
48
|
+
and refresh tokens on the server. `BffClient` connects the browser to the BFF,
|
|
49
|
+
and the React adapter uses that same client.
|
|
50
|
+
|
|
51
|
+
```mermaid
|
|
52
|
+
sequenceDiagram
|
|
53
|
+
participant Browser
|
|
54
|
+
participant App as Your app / BFF
|
|
55
|
+
participant Issuer as Udibo or your app's authorization server
|
|
56
|
+
participant API as Your API
|
|
57
|
+
Browser->>App: Start sign-in
|
|
58
|
+
App-->>Browser: Redirect to authorization endpoint
|
|
59
|
+
Browser->>Issuer: Sign in
|
|
60
|
+
Issuer-->>Browser: Redirect back with code and state
|
|
61
|
+
Browser->>App: Complete callback
|
|
62
|
+
App->>Issuer: Exchange code with PKCE and client authentication
|
|
63
|
+
Issuer-->>App: Tokens
|
|
64
|
+
App-->>Browser: Session cookie
|
|
65
|
+
Browser->>App: Request application data
|
|
66
|
+
App->>API: Access token
|
|
67
|
+
API-->>Browser: Application data, through the BFF
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`DirectClient` is for a process that holds tokens: your backend, a CLI, a native
|
|
71
|
+
app, or a public browser client. Supply a client secret only on the server. For
|
|
72
|
+
a browser app with a backend, start with the BFF guide.
|
|
73
|
+
|
|
74
|
+
`HonoResourceServer` validates access tokens and enforces scopes on API routes.
|
|
75
|
+
`HonoAuthorizationServer` issues tokens when your app hosts its own
|
|
76
|
+
authorization server. The framework-independent core accepts standard `Request`
|
|
77
|
+
and `Response` objects; Hono adapters add routing and middleware.
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
From a checkout of this repository:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
deno ci
|
|
85
|
+
deno task serve:app-with-own-auth
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Open <http://localhost:8001/> and sign in as `user` / `password`. The
|
|
89
|
+
[quickstart](docs/quickstart.md) explains what to try and which files to read.
|
|
90
|
+
All demo credentials, in-memory stores, and local HTTP settings are for
|
|
91
|
+
development.
|
|
92
|
+
|
|
93
|
+
| Example | Demonstrates |
|
|
94
|
+
| ------------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
|
95
|
+
| [Hono with own auth](examples/hono/app-with-own-auth/README.md) | App login, OAuth2 server, BFF, and protected API in one process |
|
|
96
|
+
| [Hono with external auth](examples/hono/app-with-external-auth/README.md) | Delegated sign-in, token introspection, and a BFF proxy |
|
|
97
|
+
| [Standalone API](examples/hono/api-service/README.md) | Bearer-token validation without a frontend |
|
|
98
|
+
| [Juniper with own auth](examples/juniper/app-with-own-auth/README.md) | Server-rendered React with application-owned login |
|
|
99
|
+
| [Juniper with external auth](examples/juniper/app-with-external-auth/README.md) | Server-rendered React with delegated sign-in |
|
|
100
|
+
|
|
101
|
+
## Package entrypoints
|
|
102
|
+
|
|
103
|
+
All paths below start with `@udibo/oauth2`. Each entrypoint has typed API docs
|
|
104
|
+
and examples in the [reference](https://jsr.io/@udibo/oauth2/doc).
|
|
105
|
+
|
|
106
|
+
| Subpath | Purpose |
|
|
107
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
108
|
+
| `/client` | `BffClient`, `DirectClient`, token storage, discovery caching |
|
|
109
|
+
| `/server` | Shared models, errors, scope types, and service contracts |
|
|
110
|
+
| `/server/authorization` | Authorization server, grants, token/code services, signing keys |
|
|
111
|
+
| `/server/resource` | Resource server, introspection and JWKS token readers |
|
|
112
|
+
| `/server/public-suffix` | Public Suffix List checks for optional wildcard redirect registration |
|
|
113
|
+
| `/hono/authorization-server` | Hono authorization endpoints |
|
|
114
|
+
| `/hono/resource-server` | Bearer authentication and scope middleware |
|
|
115
|
+
| `/hono/bff` | BFF routes, server-held tokens, session and pending-login stores |
|
|
116
|
+
| `/identity` | App-owned signup, login, password reset, email verification, passwordless, and protection hooks |
|
|
117
|
+
| `/identity/mfa` | TOTP, recovery codes, and MFA storage contract |
|
|
118
|
+
| `/identity/external` | Social and external OIDC sign-in for your own login pages |
|
|
119
|
+
| `/identity/migration` | Verify imported password hashes and upgrade them at login |
|
|
120
|
+
| `/hono/identity` | Hono routes for `IdentityService` |
|
|
121
|
+
| `/hono/log` | Request logger and URL helper that redact every query value |
|
|
122
|
+
| `/react` | Context, hooks, authentication guards, and callback handling |
|
|
123
|
+
| `/react/components` | Optional forms for login, signup, password reset, and MFA |
|
|
124
|
+
| `/crypto` | Random tokens, hashing, encoding, authenticated encryption |
|
|
125
|
+
| `/url` | Safe return paths and login continuation |
|
|
126
|
+
| `/cli` | Local test identity provider and OIDC signing-key generation |
|
|
127
|
+
| `/testing` | In-memory fixtures and authorization-server test helpers |
|
|
128
|
+
| `/testing/contract` | Tests for app-owned service and storage implementations |
|
|
129
|
+
| `/hono/bff/testing` | BFF session fixtures and session-store contract tests |
|
|
130
|
+
| `/react/testing` | Mock clients and providers for component tests |
|
|
131
|
+
|
|
132
|
+
## Runtime support
|
|
133
|
+
|
|
134
|
+
The library uses Web APIs. The complete suite runs on Deno. CI also builds an
|
|
135
|
+
npm-format compatibility artifact and verifies 20 entrypoints with TypeScript
|
|
136
|
+
and Node; this does not publish an npm package.
|
|
137
|
+
|
|
138
|
+
| Surface | Deno | Node | Browser | Bun |
|
|
139
|
+
| ------------------------------------------- | --------------------- | ------------------------ | ------------------------------------------- | ------------- |
|
|
140
|
+
| Clients and React | Tested, including SSR | Import/type smoke-tested | Intended for client code; no secrets | Not verified |
|
|
141
|
+
| Server, identity, Hono, crypto, URL helpers | Tested | Import/type smoke-tested | Server functionality belongs on the backend | Not verified |
|
|
142
|
+
| `/hono/bff/testing`, `/react/testing` | Tested | Import/type smoke-tested | React test helpers only | Not verified |
|
|
143
|
+
| `/testing`, `/testing/contract` | Tested | Not verified | Not supported | Not verified |
|
|
144
|
+
| `/cli` | Deno only | Not supported | Not supported | Not supported |
|
|
145
|
+
|
|
146
|
+
See [stability](docs/stability.md#runtime-support) for the support boundary.
|
|
147
|
+
|
|
148
|
+
## Before deploying
|
|
149
|
+
|
|
150
|
+
Use the [application deployment guide](docs/guides/production-deployment.md) and
|
|
151
|
+
[deployment checklist](docs/guides/hardening-checklist.md). Keep PKCE, state,
|
|
152
|
+
confidential-client authentication, and CSRF checks enabled. Replace development
|
|
153
|
+
stores with persistent implementations where needed, and run the exported
|
|
154
|
+
contract tests against those implementations.
|
|
155
|
+
|
|
156
|
+
Read [known limitations](docs/known-limitations.md) for token-revocation,
|
|
157
|
+
cookie-session, OIDC, and optional-protection behavior. Identity feature
|
|
158
|
+
examples apply to apps hosting their own login; Udibo clients use the hosted
|
|
159
|
+
sign-in flow.
|
|
160
|
+
|
|
161
|
+
## For coding agents
|
|
162
|
+
|
|
163
|
+
Start with [llms.txt](llms.txt) for the task-to-guide map and integration rules.
|
|
164
|
+
Use [llms-full.txt](llms-full.txt) when a single documentation download is
|
|
165
|
+
useful. It is generated from the same guides developers read. Prefer the
|
|
166
|
+
exported types and [extension reference](docs/trigger-points.md) when
|
|
167
|
+
implementing a custom store or callback.
|
|
168
|
+
|
|
169
|
+
## Contributing and security
|
|
170
|
+
|
|
171
|
+
Run `deno task check` and `deno task test:all` before proposing changes. See
|
|
172
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for development conventions,
|
|
173
|
+
[SECURITY.md](SECURITY.md) for private vulnerability reports, and
|
|
174
|
+
[CHANGELOG.md](CHANGELOG.md) for release history.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
`@udibo/oauth2` is security-critical software: it implements the OAuth 2.0 /
|
|
4
|
+
OpenID Connect protocol surface and password-based identity flows. We take
|
|
5
|
+
reports seriously and value the time of security researchers.
|
|
6
|
+
|
|
7
|
+
> **Status note:** the package is not yet published to a public registry. Until
|
|
8
|
+
> it is, the disclosure channel below is drafted and monitored, but the package
|
|
9
|
+
> has no external users; the process activates fully at publish.
|
|
10
|
+
|
|
11
|
+
## Supported versions
|
|
12
|
+
|
|
13
|
+
| Version | Supported |
|
|
14
|
+
| -------------- | -------------------------------- |
|
|
15
|
+
| latest `0.x` | ✅ security fixes |
|
|
16
|
+
| older releases | ❌ upgrade to the latest release |
|
|
17
|
+
|
|
18
|
+
Pre-1.0, security fixes land on the latest release only. From 1.0 on, the latest
|
|
19
|
+
minor of the current major receives fixes, and the final minor of the previous
|
|
20
|
+
major receives critical fixes for 6 months after a new major ships.
|
|
21
|
+
|
|
22
|
+
## Reporting a vulnerability
|
|
23
|
+
|
|
24
|
+
**Do not open a public issue for a security vulnerability.**
|
|
25
|
+
|
|
26
|
+
Email **security@udibo.com** with:
|
|
27
|
+
|
|
28
|
+
- A description of the vulnerability and the affected module/subpath (e.g.
|
|
29
|
+
`@udibo/oauth2/server`, `@udibo/oauth2/identity`).
|
|
30
|
+
- Reproduction steps or a proof of concept.
|
|
31
|
+
- The impact you believe it has (what an attacker gains).
|
|
32
|
+
- Any suggested remediation, if you have one.
|
|
33
|
+
|
|
34
|
+
You will receive an acknowledgment within **72 hours** and a substantive
|
|
35
|
+
assessment within **7 days**. We ask that you give us **90 days** to remediate
|
|
36
|
+
before public disclosure; we will credit you in the release notes unless you
|
|
37
|
+
prefer otherwise. We do not operate a paid bounty program.
|
|
38
|
+
|
|
39
|
+
## Scope
|
|
40
|
+
|
|
41
|
+
In scope:
|
|
42
|
+
|
|
43
|
+
- Protocol vulnerabilities (token leakage, redirect validation, PKCE bypass,
|
|
44
|
+
replay, open redirects, header trust).
|
|
45
|
+
- Identity-flow vulnerabilities (enumeration oracles, timing oracles, throttle
|
|
46
|
+
or lockout bypass, token-flow weaknesses).
|
|
47
|
+
- Cryptographic mistakes (signing, comparison, randomness).
|
|
48
|
+
|
|
49
|
+
Out of scope:
|
|
50
|
+
|
|
51
|
+
- Vulnerabilities in example apps' third-party dependencies (report upstream).
|
|
52
|
+
- Misconfiguration of an app that consumes the library contrary to documented
|
|
53
|
+
guidance (though we welcome reports that the safe path is unclear — unclear
|
|
54
|
+
docs around a security control are treated as a docs bug with priority).
|
|
55
|
+
|
|
56
|
+
## Design commitments
|
|
57
|
+
|
|
58
|
+
- **The protocol defaults are the strict ones.** PKCE is required at both the
|
|
59
|
+
authorize and token endpoints (`requirePKCE: true`), `state` is required,
|
|
60
|
+
identity flows are enumeration-safe and timing-equalized, and the built-in
|
|
61
|
+
password policy runs whether or not you configure one. Relaxing any of these
|
|
62
|
+
is an explicit option you pass.
|
|
63
|
+
- **The identity protections are opt-in objects, not defaults.** Rate limiting
|
|
64
|
+
and account lockout do **nothing** unless you construct and pass them:
|
|
65
|
+
`IdentityService` takes `rateLimiter` (and optional per-flow `rateLimiters`),
|
|
66
|
+
`lockout`, and — at the route layer — a `CaptchaProvider` you verify through
|
|
67
|
+
`verifyCaptcha`. An `IdentityService` built without them has no throttling and
|
|
68
|
+
no lockout. This is the single most consequential default in the identity
|
|
69
|
+
layer; treat wiring `rateLimiter` and `lockout` as part of deploying, not as
|
|
70
|
+
hardening you get to later. See
|
|
71
|
+
[Rate limiting, lockout, and password policy](docs/guides/production-deployment.md#rate-limiting-lockout-and-password-policy)
|
|
72
|
+
and the [hardening checklist](docs/guides/hardening-checklist.md).
|
|
73
|
+
- **Honest gaps:** deviations from the specs, and defaults that trade safety for
|
|
74
|
+
compatibility, are documented in
|
|
75
|
+
[docs/known-limitations.md](docs/known-limitations.md), not hidden.
|
|
76
|
+
- **No silent fixes:** security-relevant fixes are called out in the changelog
|
|
77
|
+
and release notes.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Object {
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether an object has a property with the specified name.
|
|
5
|
+
* @param o An object.
|
|
6
|
+
* @param v A property name.
|
|
7
|
+
*/
|
|
8
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
declare global {
|
|
13
|
+
interface Error {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
+
if (!Object.hasOwn) {
|
|
3
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
+
value: function (object, property) {
|
|
5
|
+
if (object == null) {
|
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
+
}
|
|
8
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
+
},
|
|
10
|
+
configurable: true,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers shared by the Hono adapters.
|
|
3
|
+
*
|
|
4
|
+
* Not part of the public API — use {@link HonoResourceServer} or
|
|
5
|
+
* {@link HonoAuthorizationServer} instead. Keeping the `protect` /
|
|
6
|
+
* `authenticate` / `getContext` implementations in one place lets both
|
|
7
|
+
* adapter classes stay as direct subclasses of the server type they
|
|
8
|
+
* specialize (no composition / companion objects) without duplicating the
|
|
9
|
+
* Hono-specific plumbing.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { Context, MiddlewareHandler } from "hono";
|
|
14
|
+
import type { ClientInterface } from "../../models/client.js";
|
|
15
|
+
import type { RequireConditions } from "../../models/authorization.js";
|
|
16
|
+
import type { AbstractScope, BasicScope } from "../../models/scope.js";
|
|
17
|
+
import type { AuthenticatedContext } from "../../server/resource-server.js";
|
|
18
|
+
import { ResourceServer } from "../../server/resource-server.js";
|
|
19
|
+
/**
|
|
20
|
+
* Key under which the authenticated OAuth2 context is stored on the Hono
|
|
21
|
+
* context. Namespaced to avoid collisions with other middleware.
|
|
22
|
+
*/
|
|
23
|
+
export declare const OAUTH2_CONTEXT_KEY: "@udibo/oauth2";
|
|
24
|
+
/**
|
|
25
|
+
* Variables shape to plug into `Hono<{ Variables: ... }>` so
|
|
26
|
+
* `c.get("@udibo/oauth2")` / `server.getContext(c)` is typed.
|
|
27
|
+
*/
|
|
28
|
+
export interface HonoResourceServerVariables<Client extends ClientInterface, User, S extends AbstractScope = BasicScope> {
|
|
29
|
+
/** The authenticated OAuth2 context set by the protect middleware. */
|
|
30
|
+
[OAUTH2_CONTEXT_KEY]: AuthenticatedContext<Client, User, S>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds a Hono middleware that authenticates bearer tokens, stores the
|
|
34
|
+
* authenticated context at {@link OAUTH2_CONTEXT_KEY}, and on failure returns
|
|
35
|
+
* the server's auth error response.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createProtectMiddleware<Client extends ClientInterface, User, S extends AbstractScope>(server: ResourceServer<Client, User, S>, requiredScope?: S | string): MiddlewareHandler;
|
|
38
|
+
/**
|
|
39
|
+
* Builds a Hono middleware that asserts the **already-authenticated** request
|
|
40
|
+
* (whose context a prior `protect` / `attachToken` set) carries
|
|
41
|
+
* `requiredScope`, without re-validating the token. Shared by both adapter
|
|
42
|
+
* classes' `requireScope` so the check and error stay identical to `protect`'s
|
|
43
|
+
* scope enforcement. `adapterName` names the class in the "context missing"
|
|
44
|
+
* developer error.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createRequireScopeMiddleware<Client extends ClientInterface, User, S extends AbstractScope>(server: ResourceServer<Client, User, S>, adapterName: string, requiredScope: S | string): MiddlewareHandler;
|
|
47
|
+
/**
|
|
48
|
+
* Builds a Hono middleware that asserts the **already-authenticated** request
|
|
49
|
+
* (whose context a prior `protect` set) satisfies `conditions`, without
|
|
50
|
+
* re-validating the token. Shared by both adapter classes' `require` so the
|
|
51
|
+
* checks and errors stay identical to {@link ResourceServer.assertAuthorized}.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createRequireMiddleware<Client extends ClientInterface, User, S extends AbstractScope>(server: ResourceServer<Client, User, S>, adapterName: string, conditions: RequireConditions): MiddlewareHandler;
|
|
54
|
+
/**
|
|
55
|
+
* Resolves a Hono {@link Context} or raw {@link Request} to a Request and
|
|
56
|
+
* calls the base {@link ResourceServer.authenticate} (bypassing any
|
|
57
|
+
* Context-accepting override). This is what both adapter classes'
|
|
58
|
+
* `authenticate` overrides end up calling.
|
|
59
|
+
*/
|
|
60
|
+
export declare function authenticateHonoRequest<Client extends ClientInterface, User, S extends AbstractScope>(server: ResourceServer<Client, User, S>, c: Context | Request, requiredScope?: S | string): Promise<AuthenticatedContext<Client, User, S>>;
|
|
61
|
+
/**
|
|
62
|
+
* Reads the authenticated OAuth2 context off the Hono context. Throws if
|
|
63
|
+
* `createProtectMiddleware` has not run first — the error message names the
|
|
64
|
+
* class the user invoked to make the fix obvious.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readContext<Client extends ClientInterface, User, S extends AbstractScope>(c: Context, adapterName: string): AuthenticatedContext<Client, User, S>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers shared by the Hono adapters.
|
|
3
|
+
*
|
|
4
|
+
* Not part of the public API — use {@link HonoResourceServer} or
|
|
5
|
+
* {@link HonoAuthorizationServer} instead. Keeping the `protect` /
|
|
6
|
+
* `authenticate` / `getContext` implementations in one place lets both
|
|
7
|
+
* adapter classes stay as direct subclasses of the server type they
|
|
8
|
+
* specialize (no composition / companion objects) without duplicating the
|
|
9
|
+
* Hono-specific plumbing.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { ResourceServer } from "../../server/resource-server.js";
|
|
14
|
+
/**
|
|
15
|
+
* Key under which the authenticated OAuth2 context is stored on the Hono
|
|
16
|
+
* context. Namespaced to avoid collisions with other middleware.
|
|
17
|
+
*/
|
|
18
|
+
export const OAUTH2_CONTEXT_KEY = "@udibo/oauth2";
|
|
19
|
+
/**
|
|
20
|
+
* Builds a Hono middleware that authenticates bearer tokens, stores the
|
|
21
|
+
* authenticated context at {@link OAUTH2_CONTEXT_KEY}, and on failure returns
|
|
22
|
+
* the server's auth error response.
|
|
23
|
+
*/
|
|
24
|
+
export function createProtectMiddleware(server, requiredScope) {
|
|
25
|
+
return async (c, next) => {
|
|
26
|
+
try {
|
|
27
|
+
const ctx = await baseAuthenticate(server, c.req.raw, requiredScope);
|
|
28
|
+
c.set(OAUTH2_CONTEXT_KEY, ctx);
|
|
29
|
+
await next();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return server.handleAuthError(error);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builds a Hono middleware that asserts the **already-authenticated** request
|
|
38
|
+
* (whose context a prior `protect` / `attachToken` set) carries
|
|
39
|
+
* `requiredScope`, without re-validating the token. Shared by both adapter
|
|
40
|
+
* classes' `requireScope` so the check and error stay identical to `protect`'s
|
|
41
|
+
* scope enforcement. `adapterName` names the class in the "context missing"
|
|
42
|
+
* developer error.
|
|
43
|
+
*/
|
|
44
|
+
export function createRequireScopeMiddleware(server, adapterName, requiredScope) {
|
|
45
|
+
return async (c, next) => {
|
|
46
|
+
const { scope } = readContext(c, adapterName);
|
|
47
|
+
try {
|
|
48
|
+
server.assertScope(scope, requiredScope);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return server.handleAuthError(error);
|
|
52
|
+
}
|
|
53
|
+
await next();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Builds a Hono middleware that asserts the **already-authenticated** request
|
|
58
|
+
* (whose context a prior `protect` set) satisfies `conditions`, without
|
|
59
|
+
* re-validating the token. Shared by both adapter classes' `require` so the
|
|
60
|
+
* checks and errors stay identical to {@link ResourceServer.assertAuthorized}.
|
|
61
|
+
*/
|
|
62
|
+
export function createRequireMiddleware(server, adapterName, conditions) {
|
|
63
|
+
return async (c, next) => {
|
|
64
|
+
const context = readContext(c, adapterName);
|
|
65
|
+
try {
|
|
66
|
+
server.assertAuthorized(context, conditions);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return server.handleAuthError(error);
|
|
70
|
+
}
|
|
71
|
+
await next();
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolves a Hono {@link Context} or raw {@link Request} to a Request and
|
|
76
|
+
* calls the base {@link ResourceServer.authenticate} (bypassing any
|
|
77
|
+
* Context-accepting override). This is what both adapter classes'
|
|
78
|
+
* `authenticate` overrides end up calling.
|
|
79
|
+
*/
|
|
80
|
+
export function authenticateHonoRequest(server, c, requiredScope) {
|
|
81
|
+
const request = c instanceof Request ? c : c.req.raw;
|
|
82
|
+
return baseAuthenticate(server, request, requiredScope);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Invokes the base {@link ResourceServer.authenticate} directly, bypassing
|
|
86
|
+
* any subclass override. Necessary because {@link HonoResourceServer}
|
|
87
|
+
* overrides `authenticate` to accept `Context | Request`; if this module
|
|
88
|
+
* called `server.authenticate(...)` the dispatch would land back on that
|
|
89
|
+
* override and recurse forever.
|
|
90
|
+
*/
|
|
91
|
+
function baseAuthenticate(server, request, requiredScope) {
|
|
92
|
+
// deno-lint-ignore no-explicit-any
|
|
93
|
+
const base = ResourceServer.prototype;
|
|
94
|
+
return base.authenticate.call(server, request, requiredScope);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reads the authenticated OAuth2 context off the Hono context. Throws if
|
|
98
|
+
* `createProtectMiddleware` has not run first — the error message names the
|
|
99
|
+
* class the user invoked to make the fix obvious.
|
|
100
|
+
*/
|
|
101
|
+
export function readContext(c, adapterName) {
|
|
102
|
+
const ctx = c.get(OAUTH2_CONTEXT_KEY);
|
|
103
|
+
if (!ctx) {
|
|
104
|
+
throw new Error(`OAuth2 context missing; ensure ${adapterName}.protect() middleware ` +
|
|
105
|
+
`runs before this handler.`);
|
|
106
|
+
}
|
|
107
|
+
return ctx;
|
|
108
|
+
}
|