This document explains how the Webex SDK handles OAuth authorization in Node.js environments, covering server-side authentication flows and token management.
Node.js Webex Initialization
Node.js OAuth Flow Types
Authorization Code Exchange
Server-Side Token Management
Node.js Refresh Token Management
Node.js Ready and Authorization Events
Node.js applications initialize the Webex SDK with server-side OAuth parameters:
- client_id: Your registered application ID
- client_secret: Your application's client secret (required for server-side)
- scope: Requested permissions (e.g., 'spark:all spark:kms')
- clientType: 'confidential' (default for Node.js)
Reference: See packages/@webex/plugin-authorization-node/README.md for Node.js specific configuration
The SDK automatically loads the Node.js authorization plugin:
- Environment: Detects Node.js runtime automatically
- Plugin: Loads
@webex/plugin-authorization-node - Flow Type: Defaults to Authorization Code Grant (confidential client)
Reference: Main authorization plugin in packages/@webex/plugin-authorization/README.md
- Security: Client secret can be safely stored server-side
- Token Management: Enhanced server-side token handling
- No URL Parsing: No need to parse browser URLs for tokens
- Server-to-Server: Direct API authentication without user interaction
- No Browser Redirects: Cannot redirect users to OAuth pages
- Backend Only: Requires separate frontend for user authentication flows
- Server Infrastructure: Needs server environment to run
Node.js primarily uses Authorization Code Grant:
- Frontend initiates: Browser redirects user to OAuth provider
- User authenticates: At Webex identity broker
- Code received: Authorization code sent to redirect URI
- Backend exchange: Node.js exchanges code for tokens using client secret
Node.js JWT authentication for guest/bot scenarios:
- Create JWT: Server creates JWT with guest issuer credentials
- Exchange for token: JWT exchanged for Webex access token
- API access: Use access token for Webex API calls
Reference: JWT methods in Node.js authorization plugin
For server-to-server authentication without user context:
- Direct token request: Using client_id and client_secret
- No user involvement: Pure server-to-server authentication
- Limited scope: Typically restricted to bot/integration scopes
In Node.js environment, authorization code is received via:
- Redirect URI endpoint: Your server handles the OAuth callback
- Code extraction: Extract
codeparameter from query string - State validation: Verify state parameter for CSRF protection
- Error handling: Check for OAuth error parameters
Node.js performs secure token exchange:
- POST request to OAuth token endpoint
- Parameters:
- grant_type: "authorization_code"
- client_id: Your application ID
- client_secret: Your application secret
- code: Authorization code received
- redirect_uri: Must match registered URI
Successful exchange returns:
- access_token: For API authorization
- refresh_token: For token renewal
- expires_in: Token lifetime in seconds
- token_type: Usually "Bearer"
- scope: Granted permissions
Reference: Token exchange implementation in Node.js authorization plugin
Node.js token storage considerations:
- Secure storage: Database, encrypted files, or secure key stores
- User association: Link tokens to specific user accounts
- Session management: Associate tokens with user sessions
- Encryption: Encrypt tokens at rest
Node.js can create enhanced supertoken structures:
- Standard OAuth tokens: access_token, refresh_token
- Metadata: User information, scope details
- Expiration tracking: Calculated expiry times
- Custom fields: Application-specific data
Server-side token validation:
- Expiry checking: Validate token hasn't expired
- Scope verification: Ensure token has required permissions
- Refresh triggers: Automatic refresh when near expiry
- Error handling: Handle invalid or revoked tokens
Node.js monitors token expiration through:
- Scheduled checks: Periodic token validity verification
- API response monitoring: Watch for 401 Unauthorized responses
- Proactive refresh: Refresh before expiration
- Retry logic: Automatic retry with refreshed tokens
Server-side refresh token flow:
- POST request to token endpoint
- Parameters:
- grant_type: "refresh_token"
- refresh_token: Current refresh token
- client_id: Application identifier
- client_secret: Application secret
Handle refresh response:
- Update stored tokens: Replace old tokens with new ones
- Update user sessions: Refresh tokens in active sessions
- Handle refresh failure: Re-authenticate user if refresh fails
- Concurrent requests: Handle multiple simultaneous refresh attempts
For JWT-based authentication:
- JWT expiration monitoring: Track JWT token expiry
- Automatic renewal: Create new JWT when needed
- Re-exchange process: Exchange new JWT for fresh access token
- Callback integration: Use jwtRefreshCallback for automation
Reference: JWT refresh implementation in Node.js authorization plugin
Node.js SDK initialization phases:
- Module loading: Load required Node.js modules
- Plugin initialization: Initialize Node.js authorization plugin
- Configuration validation: Validate client credentials
- Service discovery: Load Webex service endpoints
- Ready state: SDK ready for API calls
Node.js-specific events:
- ready: SDK initialized and ready for requests
- unauthorized: Token invalid or expired
- token:refresh: Token has been refreshed
- auth:error: Authentication error occurred
Check Node.js authentication status:
webex.canAuthorize: Boolean for authenticated request capabilitywebex.credentials.supertoken: Current token informationwebex.ready: Boolean for SDK initialization complete
Node.js specific error scenarios:
- Invalid client credentials: Wrong client_id or client_secret
- Network failures: Connection issues to Webex APIs
- Token expiry: Handle expired tokens gracefully
- Rate limiting: Handle API rate limit responses
- Service unavailability: Handle Webex service outages
- Main Node.js Plugin:
packages/@webex/plugin-authorization-node/ - Node.js Plugin Docs:
packages/@webex/plugin-authorization-node/README.md - WebexCore:
packages/@webex/webex-core/src/webex-core.js - Common Authorization:
packages/@webex/plugin-authorization/README.md
This package is maintained by Cisco Webex for Developers.
Pull requests welcome. Please see CONTRIBUTING.md for more details.
© 2016-2025 Cisco and/or its affiliates. All Rights Reserved.