Skip to content

example tocken-session auth on node.js over websocket

License

Notifications You must be signed in to change notification settings

Fulldroper/tocken-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The purpose of this project is to demonstrate an implementation of token-session authentication using Node.js and WebSockets.

Project Benefits

This project is useful for developers looking to understand and implement token-based authentication in a real-time communication environment.

How the Project Works

The project sets up a basic Node.js server that authenticates clients using token sessions over WebSockets. This approach ensures secure and persistent communication channels between the server and clients.

Repository and Installation

GitHub Repository

To install and run the project:

git clone https://github.com/Fulldroper/tocken-session
cd tocken-session
npm install
node index.js

Project Workflow

  1. Server Setup: Initialize the server with WebSocket support.

    const WebSocket = require('ws');
    const wss = new WebSocket.Server({ port: 8080 });
  2. Token Verification: Implement token verification for incoming connections.

    wss.on('connection', (ws, req) => {
        const token = req.url.split('?token=')[1];
        if (isValidToken(token)) {
            ws.send('Authentication successful');
        } else {
            ws.close();
        }
    });
  3. Session Management: Manage authenticated sessions.

    function isValidToken(token) {
        // Token validation logic
        return true; // Replace with actual validation
    }

Skills Gained

  • Implementing WebSocket servers in Node.js
  • Managing token-based authentication
  • Handling real-time communication securely

About

example tocken-session auth on node.js over websocket

Resources

License

Stars

Watchers

Forks