This repository contains samples for logging in with Webex Platform using Open ID Connect, known as "Login with Webex". These interactive samples demonstrate different OpenID Connect flows and provide practical examples for implementing Webex authentication in your applications.
Login with Webex lets users login to your app or service using their Webex account. Login with Webex is based on OpenID Connect, an identity layer built on the OAuth 2.0 protocol. Standard Webex Integrations use OAuth flows to obtain access tokens for making API calls on a user's behalf. Login with Webex uses those same flows, with some additional parameters, to obtain ID tokens. ID tokens are signed, Base64-encoded JSON Web Tokens (JWTs) that act as proof a user authenticated with Webex, and that contain information ("claims") about the authenticated user, such as their email or name.
Official Documentation: https://developer.webex.com/docs/login-with-webex
Try it out by choosing one of the available flows: https://webexsamples.github.io/login-with-webex
This repository demonstrates two main OpenID Connect flows:
- File:
openid3.html - Description: Simple implicit flow returning an ID token directly
- Best For: Single-page applications with minimal security requirements
- Flow Diagram: OpenID Connect ID Token Flow
- File:
pkce.html - Description: More secure flow using PKCE (Proof Key for Code Exchange)
- Best For: Public clients and mobile/SPA applications requiring enhanced security
- Flow Diagram: OpenID Connect Authorization Code + PKCE Flow
login-with-webex/
βββ src/
β βββ index.js # Express server for local development
βββ docs/ # Static web files (GitHub Pages)
β βββ index.html # Main navigation page
β βββ openid3.html # ID Token flow demo
β βββ pkce.html # PKCE flow demo
β βββ pkce.js # PKCE implementation
β βββ common.js # Shared utilities
β βββ main.css # Styling
β βββ juno.jpg # Demo images
β βββ webexlogo.png # Webex branding
βββ package.json # Node.js dependencies
βββ README.md # This file
- Node.js (v14 or higher)
- npm or yarn
- Webex Developer Account
- Webex Integration (OAuth client)
-
Clone the repository:
git clone https://github.com/WebexSamples/login-with-webex.git cd login-with-webex -
Install dependencies:
npm install
-
Start the development server:
npm start
-
Open in browser: Navigate to
http://localhost:3000
- Go to Webex Developer Portal: https://developer.webex.com/
- Create an Integration: Follow the getting started guide
- Configure Redirect URIs: Add your application URLs
- For local development:
http://localhost:3000/openid3.html - For PKCE demo:
http://localhost:3000/pkce.html - For production: Your actual domain URLs
- For local development:
openid: Required for OpenID Connectemail: Access to user's email address- Additional scopes as needed for your application
Features:
- Simple implicit flow
- Direct ID token return
- Automatic JWT parsing
- User claim extraction
Implementation:
// Redirect to Webex authorization
let authUrl = 'https://webexapis.com/v1/authorize?' +
'response_type=id_token' +
'&client_id=YOUR_CLIENT_ID' +
'&redirect_uri=YOUR_REDIRECT_URI' +
'&scope=openid%20email' +
'&state=' + Math.random() +
'&nonce=' + Math.random();
window.location.href = authUrl;ID Token Claims:
{
"sub": "user-id",
"email": "user@example.com",
"name": "John Doe",
"iss": "https://webexapis.com/v1",
"aud": "your-client-id",
"exp": 1234567890,
"iat": 1234567890
}Features:
- Enhanced security with PKCE
- Step-by-step demonstration
- Interactive form interface
- Full OAuth code flow
PKCE Implementation:
// Generate PKCE codes
function generateCodeVerifier() {
return generateRandomString(128);
}
function generateCodeChallenge(verifier) {
return base64URL(CryptoJS.SHA256(verifier));
}
// Authorization request
let authUrl = 'https://webexapis.com/v1/authorize?' +
'response_type=code' +
'&client_id=' + clientId +
'&redirect_uri=' + redirectUri +
'&scope=openid%20email' +
'&code_challenge=' + codeChallenge +
'&code_challenge_method=S256';Token Exchange:
// Exchange authorization code for access token
const tokenResponse = await fetch('https://webexapis.com/v1/access_token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
'grant_type': 'authorization_code',
'client_id': clientId,
'client_secret': clientSecret,
'code': authCode,
'code_verifier': codeVerifier,
'redirect_uri': redirectUri
})
});- Use Case: Simple applications with minimal security requirements
- Limitations: Less secure than authorization code flow
- Best Practice: Use only for public demos and testing
- Use Case: Production applications requiring enhanced security
- Security: Mitigates authorization code interception attacks
- Best Practice: Recommended for all public clients
- Never expose client secrets in client-side code
- Use server-side token exchange
- Implement proper secret management
GET https://webexapis.com/v1/authorize
Parameters:
response_type:id_tokenorcodeclient_id: Your Webex Integration Client IDredirect_uri: Registered redirect URIscope:openid email(minimum required)state: CSRF protection parameternonce: Replay attack protectioncode_challenge: PKCE code challenge (for code flow)code_challenge_method:S256(for PKCE)
POST https://webexapis.com/v1/access_token
Parameters:
grant_type:authorization_codeclient_id: Your Client IDclient_secret: Your Client Secretcode: Authorization code from callbackcode_verifier: PKCE code verifierredirect_uri: Same as authorization request
GET https://webexapis.com/v1/userinfo
Authorization: Bearer ACCESS_TOKEN
Response:
{
"sub": "user-id",
"email": "user@example.com",
"name": "John Doe",
"given_name": "John",
"family_name": "Doe",
"picture": "https://avatar.webex.com/..."
}- Start the development server:
npm start - Navigate to
http://localhost:3000 - Choose your desired flow (ID Token or PKCE)
- Enter your Webex Integration credentials
- Test the authentication flow
- Test with different user accounts
- Verify token validation
- Check claim extraction
- Test error handling scenarios
Modify main.css to customize the appearance:
- Update colors and fonts
- Modify layout and spacing
- Add your branding elements
common.js: Shared utilities and JWT parsingpkce.js: PKCE-specific implementation- Add additional claim processing
- Implement custom error handling
The repository is configured for GitHub Pages deployment:
- Static files in
/docsdirectory - Automatic deployment on push to main branch
- Live demo at: https://webexsamples.github.io/login-with-webex
For custom deployment:
- Build your static files
- Deploy the
/docsdirectory to your web server - Update redirect URIs in your Webex Integration
- Configure HTTPS (recommended for production)
function parseJwt(token) {
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const jsonPayload = decodeURIComponent(
atob(base64)
.split('')
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
.join('')
);
return JSON.parse(jsonPayload);
}function generateRandomString(length) {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
let text = '';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
function base64URL(string) {
return string
.toString(CryptoJS.enc.Base64)
.replace(/=/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_');
}{
"dependencies": {
"express": "^4.17.3",
"nodemon": "^2.0.15",
"openid-client": "^5.1.3"
}
}- express: Web framework for local development server
- nodemon: Development tool for auto-restarting server
- openid-client: OpenID Connect client library
- CryptoJS: For PKCE code generation (loaded via CDN)
- Native Web APIs: fetch, URLSearchParams, localStorage, sessionStorage
Invalid Redirect URI
- Ensure redirect URI matches exactly in your Integration settings
- Check for trailing slashes or port differences
CORS Errors
- Webex APIs support CORS for browser-based requests
- Ensure proper origin configuration in your Integration
Token Validation Failures
- Verify client ID and secret are correct
- Check token expiration times
- Ensure proper scope configuration
PKCE Generation Issues
- Verify CryptoJS library is loaded
- Check code verifier length (43-128 characters)
- Ensure code challenge uses S256 method
Enable browser developer tools to inspect:
- Network requests to Webex APIs
- Console logs for error messages
- Local storage for PKCE codes
- JWT token contents
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make your changes
- Test with both authentication flows
- Submit a pull request
- Follow existing code style
- Add comments for complex logic
- Test with multiple user scenarios
- Ensure security best practices
This project is licensed under the terms specified in the LICENSE file.
- Create an issue in this repository
- Review Login with Webex Documentation
- Contact Webex Developer Support
Made with β€οΈ by the Webex Developer Evangelism & Engineering Teams at Cisco
Repository: https://github.com/WebexSamples/login-with-webex
Live Demo: https://webexsamples.github.io/login-with-webex