@tesouro/embedded-components-widget-token 0.5.215 → 0.5.224
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/README.md
CHANGED
|
@@ -109,7 +109,7 @@ export async function POST(req: NextRequest) {
|
|
|
109
109
|
| `widgetSecret` | `string` | yes | Shared symmetric key used to encrypt the JWE. |
|
|
110
110
|
| `userId` | `string` | yes | Subject (`sub`) of the inner identity token. |
|
|
111
111
|
| `userEmail` | `string` | yes | Email claim of the inner identity token. |
|
|
112
|
-
| `organizationReference` | `string` |
|
|
112
|
+
| `organizationReference` | `string` | yes | Partner-resolved organization/business reference. Carried as `organization_reference` in the outer encrypted payload. Resolve this server-side, not from request body input. |
|
|
113
113
|
| `expirationInSeconds` | `number` | no | Token TTL in seconds. Defaults to `DEFAULT_EXPIRATION_IN_SECONDS` (480 — 8 minutes). |
|
|
114
114
|
|
|
115
115
|
Returns:
|
|
@@ -121,14 +121,16 @@ interface WidgetTokenResult {
|
|
|
121
121
|
}
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
Throws if `clientId`, `clientSecret`, or `
|
|
124
|
+
Throws if `clientId`, `clientSecret`, `widgetSecret`, or `organizationReference` is missing or empty.
|
|
125
125
|
|
|
126
126
|
### `configureCreateWidgetToken(creds)`
|
|
127
127
|
|
|
128
128
|
Binds `clientId`, `clientSecret`, `widgetSecret`, and optional defaults for
|
|
129
129
|
`organizationReference` and `expirationInSeconds`, and returns a function that
|
|
130
130
|
only takes per-request `userId` / `userEmail` plus optional per-call overrides
|
|
131
|
-
for `organizationReference` and `expirationInSeconds`.
|
|
131
|
+
for `organizationReference` and `expirationInSeconds`. `organizationReference`
|
|
132
|
+
is still required: the returned function throws unless it is bound here or
|
|
133
|
+
passed per call.
|
|
132
134
|
|
|
133
135
|
### `DEFAULT_EXPIRATION_IN_SECONDS`
|
|
134
136
|
|
|
@@ -150,9 +152,9 @@ for `organizationReference` and `expirationInSeconds`.
|
|
|
150
152
|
|
|
151
153
|
The encrypted payload is an RFC 8693 token-exchange request whose
|
|
152
154
|
`subject_token` is an unsigned identity JWT (`alg: none`) bearing the user's
|
|
153
|
-
`sub`, `email`, `iss`, `aud`, `iat`, and `exp` claims.
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
`sub`, `email`, `iss`, `aud`, `iat`, and `exp` claims. `organizationReference`
|
|
156
|
+
is minted at the outer encrypted payload level as `organization_reference`; it
|
|
157
|
+
is not added to the inner `subject_token`.
|
|
156
158
|
|
|
157
159
|
## License
|
|
158
160
|
|
package/dist/index2.js
CHANGED
|
@@ -4,6 +4,7 @@ import { EncryptJWT as t } from "jose";
|
|
|
4
4
|
var n = 480;
|
|
5
5
|
async function r({ clientId: n, clientSecret: r, widgetSecret: i, userId: a, userEmail: o, organizationReference: s, expirationInSeconds: c = 480 }) {
|
|
6
6
|
if (!i || !n || !r) throw Error("Missing required parameters for widget token generation: clientId, clientSecret, and widgetSecret are required");
|
|
7
|
+
if (typeof s != "string" || !s.trim()) throw Error("Missing required parameter for widget token generation: organizationReference is required");
|
|
7
8
|
let l = Math.floor(Date.now() / 1e3), u = l + c, d = new TextEncoder().encode(i), f = {
|
|
8
9
|
sub: a,
|
|
9
10
|
email: o,
|
|
@@ -23,7 +24,7 @@ async function r({ clientId: n, clientSecret: r, widgetSecret: i, userId: a, use
|
|
|
23
24
|
iat: l,
|
|
24
25
|
iss: n,
|
|
25
26
|
jti: e.randomUUID(),
|
|
26
|
-
|
|
27
|
+
organization_reference: s,
|
|
27
28
|
subject_token: p,
|
|
28
29
|
subject_token_type: "urn:ietf:params:oauth:token-type:access_token"
|
|
29
30
|
};
|
|
@@ -8,13 +8,10 @@ export interface CreateWidgetTokenParams {
|
|
|
8
8
|
/**
|
|
9
9
|
* The partner's stable, opaque identifier for the business/organization
|
|
10
10
|
* (SMB grouping) the applicant belongs to. Minted into the outer JWE payload
|
|
11
|
-
* as `organization_reference`
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* MUST be resolved server-side from the partner's organization config — never
|
|
15
|
-
* accept this value from the browser.
|
|
11
|
+
* as the required `organization_reference` claim. Resolve it server-side,
|
|
12
|
+
* never from the browser.
|
|
16
13
|
*/
|
|
17
|
-
organizationReference
|
|
14
|
+
organizationReference: string;
|
|
18
15
|
expirationInSeconds?: number;
|
|
19
16
|
}
|
|
20
17
|
export interface WidgetTokenResult {
|
|
@@ -22,5 +19,5 @@ export interface WidgetTokenResult {
|
|
|
22
19
|
exp: number;
|
|
23
20
|
}
|
|
24
21
|
export declare function createWidgetToken({ clientId, clientSecret, widgetSecret, userId, userEmail, organizationReference, expirationInSeconds, }: CreateWidgetTokenParams): Promise<WidgetTokenResult>;
|
|
25
|
-
export declare function configureCreateWidgetToken({ clientId, clientSecret, widgetSecret, organizationReference: defaultOrganizationReference, expirationInSeconds: defaultExpiration, }: Pick<CreateWidgetTokenParams, 'clientId' | 'clientSecret' | 'widgetSecret' | '
|
|
22
|
+
export declare function configureCreateWidgetToken({ clientId, clientSecret, widgetSecret, organizationReference: defaultOrganizationReference, expirationInSeconds: defaultExpiration, }: Pick<CreateWidgetTokenParams, 'clientId' | 'clientSecret' | 'widgetSecret' | 'expirationInSeconds'> & Partial<Pick<CreateWidgetTokenParams, 'organizationReference'>>): ({ userId, userEmail, organizationReference, expirationInSeconds, }: Pick<CreateWidgetTokenParams, "userId" | "userEmail" | "expirationInSeconds"> & Partial<Pick<CreateWidgetTokenParams, "organizationReference">>) => Promise<WidgetTokenResult>;
|
|
26
23
|
//# sourceMappingURL=createWidgetToken.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWidgetToken.d.ts","sourceRoot":"","sources":["../../src/lib/createWidgetToken.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAA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