@tesouro/embedded-components-widget-token 0.7.40 → 0.7.44
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 +15 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,42 +59,18 @@ const { widgetToken, exp } = await mintWidgetToken({
|
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### In a route handler
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const mintWidgetToken = configureCreateWidgetToken({
|
|
70
|
-
clientId: process.env.TESOURO_CLIENT_ID!,
|
|
71
|
-
clientSecret: process.env.TESOURO_CLIENT_SECRET!,
|
|
72
|
-
widgetSecret: process.env.TESOURO_WIDGET_SECRET!,
|
|
73
|
-
organizationReference: process.env.TESOURO_ORGANIZATION_REFERENCE!,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
export async function POST(req: NextRequest) {
|
|
77
|
-
// Resolve the user from YOUR authenticated session — NEVER from the request
|
|
78
|
-
// body. This route hands back a valid widget token for whatever identity you
|
|
79
|
-
// pass in, so reading `userId` / `userEmail` from `req.json()` would let any
|
|
80
|
-
// caller mint a token impersonating someone else. Swap `getSession` for your
|
|
81
|
-
// own server-side session verification (signed cookie, bearer token, etc.).
|
|
82
|
-
const session = await getSession(req);
|
|
83
|
-
if (!session) {
|
|
84
|
-
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { widgetToken, exp } = await mintWidgetToken({
|
|
88
|
-
userId: session.userId,
|
|
89
|
-
userEmail: session.userEmail,
|
|
90
|
-
});
|
|
91
|
-
return NextResponse.json({ widgetToken, exp });
|
|
92
|
-
}
|
|
93
|
-
```
|
|
64
|
+
Call the factory from an authenticated route on your server and return
|
|
65
|
+
`{ widgetToken, exp }` to the browser.
|
|
66
|
+
[Getting started](https://components.tesouro.com/components/getting-started)
|
|
67
|
+
has a complete Next.js route handler and the provider that calls it.
|
|
94
68
|
|
|
95
69
|
> **Identity must come from the server, not the caller.** Resolve `userId`,
|
|
96
|
-
> `userEmail`, and `organizationReference` from your authenticated session
|
|
97
|
-
>
|
|
70
|
+
> `userEmail`, and `organizationReference` from your authenticated session,
|
|
71
|
+
> never from the request body. `organizationReference` names the business the
|
|
72
|
+
> user belongs to, so bind it once in `configureCreateWidgetToken` only when
|
|
73
|
+
> every user of that server belongs to the same business. Your route mints a valid
|
|
98
74
|
> token for whatever identity it receives, so trusting client-supplied identity
|
|
99
75
|
> lets any caller impersonate another user.
|
|
100
76
|
|
|
@@ -156,6 +132,12 @@ The encrypted payload is an RFC 8693 token-exchange request whose
|
|
|
156
132
|
is minted at the outer encrypted payload level as `organization_reference`; it
|
|
157
133
|
is not added to the inner `subject_token`.
|
|
158
134
|
|
|
135
|
+
Backends that don't run Node build the same token from the widget token
|
|
136
|
+
protocol in Authentication › User token, in the
|
|
137
|
+
[Embedded Banking](https://docs.tesouro.com/embedded-banking/guides/authentication/user-token)
|
|
138
|
+
or [FinOps](https://docs.tesouro.com/finops/guides/authentication/user-token)
|
|
139
|
+
docs.
|
|
140
|
+
|
|
159
141
|
## License
|
|
160
142
|
|
|
161
143
|
Apache-2.0
|