Connecting to Third-Party Systems
Connecting to Third-Party Systems
Connecting to Third-Party Systems
Integrations with third-party systems are a common requirement for custom frontends. B2B operations are often data-heavy and can potentially involve information from multiple systems, making this topic of third-party integrations especially relevant for the B2B Buyer Portal.
Third-party API integrations can be fairly straightforward in a traditional web application with a server-side layer. The Buyer Portal, however, is a client-side application. The portal already handles user authentication with one API - namely, the B2B GraphQL API. How do we translate this authentication into secure access to a third-party system from the browser?
Let’s define a hypothetical scenario for a third-party integration. Your B2B operations might involve using a CRM system for managing support cases opened by buyers for their orders. And users of your storefront might need to see support case information when viewing their orders, sourced from the CRM. Assume that the B2B Edition company a user is associated with has a corresponding entity in the CRM system.
Any API requests to the CRM must originate in the browser, where the client app runs. How do you ensure these requests are properly and securely authenticated? It’s unlikely the CRM implements a storefront API (like the B2B GraphQL API) with auth tokens designed to be used in the open. (Even if so, we would need a single sign-on solution to avoid managing two logins for the user.)
The challenges can be summarized this way:
Solving our client-side API challenges will therefore be similarly two-fold:
Since our hypothetical middleware serves primarily to control the flow of data to a UI, it can be thought of as implementing a “backend for frontend” (BFF) pattern.
A key capability of this middleware would be to capitalize on the user’s existing authentication with the B2B GraphQL API to verify the user’s (and company’s) identity. It could then issue its own token.
A high-level overview of this strategy:
Building out a middleware or BFF like this is beyond the scope of this course, but we’ll simulate this workflow from the Buyer Portal perspective in the next lab.
Json Web Tokens (JWTs) are well suited for the type of token to be issued by the middleware in our hypothetical scenario. JWTs are an open industry standard for transmitting claims between two parties, and they are designed specifically to be transmitted in the open (such as publicly in the browser) while still being trusted.
A JWT is an encoded version of information represented in simple Json format, signed by a secret that is not shared publicly. So while the content of a JWT exposed in the browser can be tampered with, the middleware application uses the secret to verify the integrity of the token and will reject a token that has been altered.
The B2B GraphQL API token is, itself, a JWT. This is why it is secure to transmit publicly from the browser.
The straightforward method described above is a homegrown solution relying on the Buyer Portal’s existing authentication with the B2B GraphQL API. For the type of integrations we’re describing in this section, another option is to use a full single sign-on (SSO) solution to manage authentication.
Popular third-party SSO providers (such as Okta or OneLogin) can be used to manage user authentication and authorization to multiple systems. In a SSO flow, the user’s initial authentication would be done through the SSO provider, and the SSO would manage appropriate credentials for multiple systems (in our scenario, the B2B GraphQL API and the middleware application).
SSO can be an appropriate solution if your authentication requirements are complex. If replacing the built-in Buyer Portal login flow with a SSO integration, note the key capability of the B2B REST Management API to issue storefront tokens.
In Headless
In Catalyst or other headless storefronts, you have more flexibility for integration strategy. You might opt to make third-party API requests in the server-side layer already part of your storefront application. This bypasses the client-side challenges discussed here.