@swishapp/auth-proxy package.
If you’re using a Shopify theme, skip this page. Token creation is already
handled for you.
Installation
Quick start
Create an auth proxy instance and exposecreateToken as a server route. The proxy validates the request, creates a token using the Swish API, and returns it to the client.
Configuration
How it works
WhencreateToken(request) is called:
- The proxy calls your
authenticatecallback to identify the customer. - It reads the request body and forwards it to
POST /profiles/tokenon the Swish API, authenticated with yourauthToken. - If the body contains a
customerfield, the proxy validates that it matches the authenticated customer ID. A mismatch returns a401response. This prevents a client from requesting tokens for other customers. - The upstream response is returned directly to the client.
onError and returned to the client as a 401.
Framework examples
Hydrogen
Expose the proxy as a Remix action on a server route.app/routes/api.swish-token.ts
Next.js
Expose the proxy as a Route Handler.app/api/swish-token/route.ts
SDK configuration
Configure the SDK to use your auth proxy route by settingauth.tokenUrl to match the server endpoint you created above.
/apps/wishlist/api/profiles/token and does not need to be set.