Documentation

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

Sandbox or live

environment has no default, on purpose. Sandbox and live are separate apps with separate credentials, accounts and endpoints:

environmentSign-in pageAPIWho can sign in
'sandbox'www.sandbox.paypal.comhttps://api-m.sandbox.paypal.comsandbox test accounts only
'live'www.paypal.comhttps://api-m.paypal.comreal 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 from VITNODE_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:

.env
PAYPAL_CLIENT_ID=AYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PAYPAL_CLIENT_SECRET=EKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Add 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:

src/vitnode.api.config.ts (excerpt)
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:

.env
VITNODE_WEB_URL=https://forum-dev.example.com
VITNODE_API_URL=https://forum-dev.example.com

Scopes and profile fields

SettingValue
Scopesopenid email profile
Token authHTTP Basic with the client ID and secret
Account IDuser_id
Email trustedthe primary emails entry with confirmed: true, otherwise email with email_verified: true
Profile fieldsfirst 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.