SSO
PayPal
Add Log in with PayPal to VitNode. Enable it on a PayPal REST app, pick sandbox or live, register the HTTPS return URL and wire up the adapter.
Add a Continue with PayPal button that signs people in with their PayPal account. This is authentication only. VitNode never touches payments or balances and asks for no payment permissions, so taking payments needs a separate integration.
Before you begin
- A running VitNode app. This page covers only the PayPal parts; SSO setup explains the shared steps and where the API's
.envand config live. - A PayPal developer account.
- A public HTTPS return URL. PayPal's documentation does not say a
localhostreturn URL works, so test locally through a tunnel (see Develop locally).
Sandbox or live
environment has no default, on purpose. Sandbox and live are separate apps with separate credentials, accounts and endpoints:
environment | Sign-in page | API | Who can sign in |
|---|---|---|---|
'sandbox' | www.sandbox.paypal.com | https://api-m.sandbox.paypal.com | sandbox test accounts only |
'live' | www.paypal.com | https://api-m.paypal.com | real PayPal accounts |
Sandbox credentials fail against live, and the other way round. A common pattern is environment: process.env.PAYPAL_ENVIRONMENT === 'live' ? 'live' : 'sandbox'.
Set up Log in with PayPal
Create a REST app
In the PayPal Developer Dashboard, choose Sandbox or Live at the top, open Apps & Credentials and press Create App.
Enable Log in with PayPal
Open the app, scroll to Features (or Other features) and tick Log in with PayPal, then open Advanced Settings.
Add the return URL and user information
In Advanced Settings:
- Return URL:
https://your-domain.com/login/sso/paypal. VitNode builds it fromVITNODE_WEB_URL, so it must match exactly. - User information: select Email, plus the name if your dashboard offers it. PayPal's guide names only email, account verification status and PayPal account ID, so the exact options may differ.
- Add the Privacy policy URL and User agreement URL PayPal asks for, then save.
Copy the credentials
The app page shows the Client ID and Secret for the environment you chose. Keep them server-side:
PAYPAL_CLIENT_ID=AYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PAYPAL_CLIENT_SECRET=EKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAdd the adapter
Add PayPalSSOApiPlugin to authorization.ssoAdapters in the API's vitnode.api.config.ts (where it lives), next to any adapters you already have. Keep the rest of the config as it is:
import { PayPalSSOApiPlugin } from '@vitnode/core/api/adapters/sso/paypal'
import { buildApiConfig } from '@vitnode/core/vitnode.config'
export const vitNodeApiConfig = buildApiConfig({
// ...
authorization: {
ssoAdapters: [
// ...
PayPalSSOApiPlugin({
clientId: process.env.PAYPAL_CLIENT_ID,
clientSecret: process.env.PAYPAL_CLIENT_SECRET,
environment: 'sandbox',
}),
],
},
})No authorization block yet? Create one with just ssoAdapters, as in the SSO setup. Then restart the dev server, since .env and the API config are only read at start-up.
Check the result
For sandbox, create a personal test account under Testing tools ā Sandbox accounts. Open /login on your HTTPS domain, press the PayPal button under Continue with, sign in with the test account and agree. You return to /login/sso/paypal signed in.
Go live
Repeat the setup with Live selected, switch the variables to the live credentials and set environment: 'live'. Saving Log in with PayPal on a live app submits it for review automatically. PayPal says the review typically takes a few weeks and every scope needs its approval; sandbox apps need no review. Changes to the return URL can also take a few hours to apply.
Develop locally
Use an HTTPS tunnel (for example Cloudflare Tunnel or ngrok), add its return URL to the sandbox app, and point VitNode at it:
VITNODE_WEB_URL=https://forum-dev.example.com
VITNODE_API_URL=https://forum-dev.example.comScopes and profile fields
| Setting | Value |
|---|---|
| Scopes | openid email profile |
| Token auth | HTTP Basic with the client ID and secret |
| Account ID | user_id |
| Email trusted | the primary emails entry with confirmed: true, otherwise email with email_verified: true |
| Profile fields | first name, last name |
Troubleshooting
- "invalid_client". You used sandbox credentials with
environment: 'live', or the other way round. - PayPal shows "We're sorry, things don't appear to be working". The return URL in Advanced Settings differs from
{VITNODE_WEB_URL}/login/sso/paypal, or is not HTTPS. - Signed in, but asked to confirm an email. Email is not selected under the user information, or the PayPal account's email is unconfirmed. See Email confirmation.