Skip to content

A specialized game account authentication service with dual-token architecture and multi-platform login support.

License

Notifications You must be signed in to change notification settings

go-pantheon/lares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Lares Game Account Authentication Service

Specialized game account authentication service with dual-token architecture and multi-platform login support

Build Status Latest Release Kratos GoDoc Go Report Card License Ask DeepWiki

English | ไธญๆ–‡

About Lares

Lares is a specialized game account authentication service that provides secure, high-performance identity verification for modern gaming applications. Featuring a dual-token architecture (Session + AuthToken), native support for Apple/Google/Facebook login, and game-optimized features like color-based character selection and server routing, Lares transforms complex authentication challenges into simple solutions that game developers can implement quickly while maintaining enterprise-grade security and performance at scale.

About the go-pantheon Ecosystem

go-pantheon is an out-of-the-box game server framework that provides high-performance, highly available game server cluster solutions based on microservice architecture. Lares serves as the authentication hub, collaborating with other core services to form a complete game service ecosystem:

  • Roma: Game core business service, responsible for game logic processing and data management
  • Janus: Gateway service, responsible for client connection handling and request forwarding
  • Lares: Account authentication service, responsible for user authentication and account management
  • Senate: Backend management service, providing operational management interfaces

Core Advantages

๐Ÿ”’ Secure & Reliable

  • Enterprise-grade Encryption: Multi-layer encryption protection to prevent account theft
  • Replay Attack Prevention: Ensures uniqueness and security of each request
  • Third-party Platform Verification: Supports secure integration with mainstream social platforms

๐ŸŒ Multi-platform Login

  • Traditional Account: Username/password registration and login
  • Apple Login: Supports both Web and App platforms
  • Google Login: Standard OAuth2 flow
  • Facebook Login: Quick social account integration

โšก High-performance Architecture

  • Microservice Design: Supports horizontal scaling and distributed deployment
  • Dual Protocol Support: Provides both gRPC and HTTP interfaces
  • Fast Token Generation: Efficient token generation and verification mechanisms

๐ŸŽฎ Seamless Game Ecosystem Integration

  • Independent Verification: Janus gateway can verify tokens independently for faster response
  • Operational Support: Built-in announcement system supporting game operations
  • Flexible Extension: Modular design, easy to add new features

System Architecture

System Architecture Overview

Component Relationship Diagram:

graph TB
    Client["๐ŸŽฎ Game Client"]
    Lares["๐Ÿ” Lares<br/>(Authentication Service)"]
    Janus["๐Ÿ”ฐ Janus<br/>(Gateway Service)"]
    Senate["๐Ÿ“Š Senate<br/>(Management Service)"]

    subgraph Roma["โš™๏ธ Roma Game Service Cluster"]
        direction LR
        Player["๐Ÿ‘ค Player Service"]
        Room["๐Ÿ  Room Service"]
        Team["๐Ÿค Team Service"]
        Other["... Other Services"]
    end

    subgraph ThirdParty["๐ŸŒ Third-party Platforms"]
        direction LR
        Apple["Apple"]
        Google["Google"]
        Facebook["Facebook"]
    end

    subgraph OwnAccount["๐Ÿ” Native Account System"]
        direction LR
        Register["๐Ÿ“ Register/Login"]
        Session["๐ŸŽซ Session Management"]
        Renewal["๐Ÿ”„ Session Renewal"]
    end

    Client -->|"1.Authentication Request"| Lares
    ThirdParty -->|"Token Verification"| Lares
    OwnAccount -->|"Username/Password & Session Verification"| Lares
    Lares -->|"Return Account Token + Session"| Client
    Client -->|"2.Game Connection + Token"| Janus
    Janus -->|"3.gRPC Call"| Player
    Janus -->|"gRPC Call"| Room
    Janus -->|"gRPC Call"| Team
    Player -->|"Business Response"| Janus
    Room -->|"Business Response"| Janus
    Team -->|"Business Response"| Janus
    Janus -->|"4.Game Data"| Client
    Lares -.->|"User Data"| Senate

    classDef clientStyle fill:#e1f5fe,stroke:#01579b,stroke-width:2px
    classDef laresStyle fill:#fff3e0,stroke:#f57c00,stroke-width:3px
    classDef serviceStyle fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
    classDef gatewayStyle fill:#e8f5e8,stroke:#1b5e20,stroke-width:2px
    classDef thirdPartyStyle fill:#fce4ec,stroke:#c2185b,stroke-width:2px
    classDef ownAccountStyle fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px

    class Client clientStyle
    class Lares laresStyle
    class Janus gatewayStyle
    class Senate serviceStyle
    class Player,Room,Team,Other serviceStyle
    class Apple,Google,Facebook thirdPartyStyle
    class Register,Session,Renewal ownAccountStyle
Loading

Lares Internal Architecture

Lares Service Architecture Diagram:

graph TB
    subgraph Lares["๐Ÿ” Lares Account Authentication Service"]
        direction TB

        subgraph Services["Microservice Modules"]
            direction LR

            subgraph Account["๐Ÿ‘ค Account Service"]
                AccountAPI["API Layer"]
                AccountBiz["Business Layer"]
                AccountData["Data Layer"]
            end

            subgraph Notice["๐Ÿ“ข Notice Service"]
                NoticeAPI["API Layer"]
                NoticeBiz["Business Layer"]
                NoticeData["Data Layer"]
            end

            subgraph Future["๐Ÿ”ฎ Future Services"]
                ServerAPI["Server Management API"]
                ServerBiz["Server Management Business"]
                ServerData["Server Management Data"]
            end
        end

        subgraph Security["๐Ÿ›ก๏ธ Security Components"]
            direction LR
            JWT["JWT Validator"]
            AES["AES Encryptor"]
            Password["Password Hasher"]
            Session["Session Manager"]
        end

        subgraph Platform["๐ŸŒ Platform Integration"]
            direction LR
            AppleDomain["Apple Verification"]
            GoogleDomain["Google Verification"]
            FacebookDomain["Facebook Verification"]
        end
    end

    subgraph Infrastructure["Infrastructure"]
        direction LR
        PostgreSQL["PostgreSQL<br/>User Data Storage"]
        Etcd["etcd<br/>Service Discovery"]
    end

    subgraph External["External Services"]
        direction LR
        AppleAuth["Apple Authentication Service"]
        GoogleAuth["Google Authentication Service"]
        FacebookAuth["Facebook Authentication Service"]
    end

    AccountData -.->|"User Data"| PostgreSQL
    NoticeData -.->|"Notice Data"| PostgreSQL
    AccountAPI -.->|"Service Registration"| Etcd
    NoticeAPI -.->|"Service Registration"| Etcd

    AppleDomain -.->|"Token Verification"| AppleAuth
    GoogleDomain -.->|"Token Verification"| GoogleAuth
    FacebookDomain -.->|"Token Verification"| FacebookAuth

    AccountBiz -.->|"Use"| JWT
    AccountBiz -.->|"Use"| AES
    AccountBiz -.->|"Use"| Password
    AccountBiz -.->|"Use"| Session

    classDef serviceStyle fill:#fff3e0,stroke:#f57c00,stroke-width:2px
    classDef securityStyle fill:#e8f5e8,stroke:#388e3c,stroke-width:2px
    classDef infraStyle fill:#fce4ec,stroke:#c2185b,stroke-width:2px
    classDef externalStyle fill:#f3e5f5,stroke:#4a148c,stroke-width:2px

    class AccountAPI,AccountBiz,AccountData,NoticeAPI,NoticeBiz,NoticeData,ServerAPI,ServerBiz,ServerData serviceStyle
    class JWT,AES,Password,Session,AppleDomain,GoogleDomain,FacebookDomain securityStyle
    class PostgreSQL,Redis,Etcd infraStyle
    class AppleAuth,GoogleAuth,FacebookAuth externalStyle
Loading

Authentication Flow Details

Complete User Authentication Flow:

sequenceDiagram
    participant C as ๐ŸŽฎ Game Client
    participant L as ๐Ÿ” Lares
    participant TP as ๐ŸŒ Third-party Platform
    participant OA as ๐Ÿ” Native Account System
    participant J as ๐Ÿ”ฐ Janus
    participant R as โš™๏ธ Roma Service

    Note over C,R: Method 1: Third-party Platform Login
    C->>L: 1.1 Send third-party login request
    L->>TP: 1.2 Verify third-party token
    TP-->>L: 1.3 Return user information
    L->>L: 1.4 Generate/update user account
    L->>L: 1.5 Generate Account Token + Session
    L-->>C: 1.6 Return Account Token + Session

    Note over C,R: Method 2: Native Account Registration/Login
    C->>L: 2.1 Send register/login request (username + password)
    L->>OA: 2.2 Verify account credentials
    OA-->>L: 2.3 Return verification result
    L->>L: 2.4 Generate/update user account
    L->>L: 2.5 Generate Account Token + Session
    L-->>C: 2.6 Return Account Token + Session

    Note over C,R: Method 3: Session Quick Login
    C->>L: 3.1 Send Session login request
    L->>OA: 3.2 Verify Session validity
    OA-->>L: 3.3 Session verification passed
    L->>L: 3.4 Generate new Account Token
    L-->>C: 3.5 Return Account Token

    Note over C,R: Method 4: Session Renewal (Independent Operation)
    C->>L: 4.1 Send Session renewal request
    L->>OA: 4.2 Verify Session validity
    OA-->>L: 4.3 Session verification passed
    L->>L: 4.4 Extend Session validity
    L-->>C: 4.5 Return new renewed Session

    Note over C,R: Game Connection Phase
    C->>J: 5.1 Establish TCP connection
    C->>J: 5.2 Send handshake request (with Token)
    J->>J: 5.3 Verify Account Token
    J-->>C: 5.4 Handshake success response

    Note over C,R: Game Interaction Phase
    C->>J: 6.1 Send game protocol
    J->>R: 6.2 Forward as gRPC call
    R->>R: 6.3 Process game logic
    R-->>J: 6.4 Return processing result
    J-->>C: 6.5 Forward game response
Loading

Core Concepts

๐Ÿ”‘ Session Mechanism

Session is the player login identifier cached on the client side, used to maintain user login status:

message Session {
  int64 account_id = 1;    // Account ID
  int64 timeout = 2;       // Expiration timestamp
  string key = 3;          // Random string
}

Features:

  • ๐Ÿ•’ Auto Expiration: Ensures security, prevents long-term abuse
  • ๐Ÿ” Secure Storage: Encrypted protection, prevents session hijacking
  • ๐Ÿ”„ Flexible Renewal: Supports extending validity period
  • ๐Ÿ“ฑ No Repeated Login: Improves user experience

๐ŸŽซ AuthToken Authentication Token

AuthToken is the verification information carried by the client when handshaking with the Janus gateway, containing complete user identity and routing information:

message AuthToken {
  string rand = 1;         // Random string for replay attack prevention
  string color = 2;        // Color identifier
  int64 account_id = 3;    // Account ID
  int64 server_id = 4;     // Server ID
  int64 timeout = 5;       // Expiration timestamp
  int32 location = 6;      // Location information
  OnlineStatus status = 7; // Access identifier
  bool unencrypted = 8;    // Whether to disable encryption for this connection
}

Features:

  • ๐Ÿ”’ Secure Transmission: Encrypted protection, ensures data security
  • ๐Ÿ”„ Complete Information: Contains user connection information, no additional queries needed
  • ๐Ÿ›ก๏ธ Attack Prevention: Ensures token uniqueness and security
  • ๐ŸŽฏ Smart Routing: Supports load balancing and distribution
  • โšก Fast Verification: Gateway independent verification, faster response
  • ๐Ÿ“ Status Tracking: Supports distributed game logic

Service Modules

Lares currently supports the following service modules:

Module Status Description Functions
Account โœ… Implemented Account management User registration, login, third-party platform integration
Notice โœ… Implemented Announcement system Notice publishing, management, client push
Server ๐Ÿ”ฎ Planned Game server management Game server creation, management, load balancing

Authentication Support

Authentication Method Status Description Features
Username/Password โœ… Full Support Traditional account reg/login Secure encryption, password strength validation
Apple Sign In โœ… Full Support Apple official login Supports Web/App dual platform
Google OAuth โœ… Full Support Google account login Standard OAuth2 flow
Facebook Login โœ… Full Support Facebook social login Quick social access

Technology Stack

Lares uses the following core technologies:

Technology/Component Purpose Version
Go Primary development language 1.24+
go-kratos Microservice framework v2.8.4
gRPC Inter-service communication v1.73.0
Protobuf Data serialization v1.36.6
etcd Service discovery & registry v3.6.1
PostgreSQL Main database v5.7.5
OpenTelemetry Distributed tracing v1.37.0
Prometheus Monitoring system v1.22.0
Google Wire Dependency injection v0.6.0
JWT Token verification v4.5.2
Argon2 Password hashing Built-in

Quick Start

Requirements

  • Go 1.24+ - Primary development language
  • PostgreSQL 13+ - Main database
  • etcd 3.5+ - Service discovery and configuration center
  • protoc - Protocol Buffers compiler

Installation

# 1. Clone the project
git clone https://github.com/go-pantheon/lares.git
cd lares

# 2. Initialize development environment
make init

# 3. Install dependencies
go mod download

Configuration

# 1. Copy configuration template
cp app/account/configs.tmpl/config.yaml app/account/configs/config.yaml

# 2. Edit configuration file
vim app/account/configs/config.yaml

Key Configuration Items:

# Service configuration
server:
  http:
    addr: 0.0.0.0:8001
  grpc:
    addr: 0.0.0.0:9001

# Database configuration
data:
  postgresql:
    source: "postgres://user:password@localhost:5432/lares?sslmode=disable"

# Third-party platform configuration
platform:
  apple:
    client_id: "your_apple_client_id"
    team_id: "your_apple_team_id"
    key_id: "your_apple_key_id"
  google:
    aud: "your_google_client_id"
  facebook:
    app_id: "your_facebook_app_id"
    app_secret: "your_facebook_app_secret"

# Security configuration
secret:
  token_key: "your_32_byte_token_encryption_key"
  session_key: "your_32_byte_session_encryption_key"
  platform_key: "your_32_byte_platform_encryption_key"

Start Services

# 1. Generate code
make generate

# 2. Build service
make build

# 3. Start account service
make run app=account

# 4. Start notice service
make run app=notice

Service Verification

# Check service status
curl http://localhost:8001/accounts/v1/dev/ping

# Test user registration
curl -X POST http://localhost:8001/accounts/v1/username/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "SecurePassword123!",
    "color": "blue"
  }'

API Documentation

Account Management Interface

User Registration

POST /accounts/v1/username/register
Content-Type: application/json

{
  "username": "player123",
  "password": "SecurePassword123!",
  "color": "blue"
}

# Response Example
{
  "info": {
    "account_id": "encoded_account_id",
    "register": true,
    "token": "encrypted_auth_token",      # AuthToken, for gateway handshake
    "token_timeout": 1704067200,
    "session": "encrypted_session",       # Session, client cache
    "session_timeout": 1704153600,
    "state": "random_state_string"
  }
}

User Login

POST /accounts/v1/username/login
Content-Type: application/json

{
  "username": "player123",
  "password": "SecurePassword123!",
  "color": "blue"
}

# Response Example
{
  "info": {
    "account_id": "encoded_account_id",
    "register": false,
    "token": "encrypted_auth_token",      # AuthToken, for gateway handshake
    "token_timeout": 1704067200,
    "session": "encrypted_session",       # Session, client cache
    "session_timeout": 1704153600,
    "state": "random_state_string"
  }
}

Third-party Login

# Apple Login
POST /accounts/v1/apple/login
Content-Type: application/json

{
  "token": "apple_id_token",
  "color": "blue"
}

# Google Login
POST /accounts/v1/google/login
Content-Type: application/json

{
  "token": "google_id_token",
  "color": "blue"
}

# Facebook Login
POST /accounts/v1/fb/login
Content-Type: application/json

{
  "token": "facebook_access_token",
  "color": "blue"
}

Get Game Token

POST /accounts/v1/token
Content-Type: application/json

{
  "account_id": "encoded_account_id",
  "session": "encrypted_session_token",
  "color": "blue"
}

Refresh Session

POST /accounts/v1/refresh
Content-Type: application/json

{
  "account_id": "encoded_account_id",
  "session": "current_session_token"
}

Notice System Interface

Get Notice List

GET /notices/v1/list
Content-Type: application/json

{
  "page": 1,
  "size": 10
}

Contributing

We welcome contributions! Please follow the process below:

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Create a Pull Request

Development Standards

  • Follow Go official code standards
  • Use golangci-lint for code checking
  • Write unit tests, ensure code coverage > 80%
  • Update relevant documentation and API descriptions
  • Ensure CI/CD pipeline passes

License

This project is open sourced under the MIT License.


โœจ **Lares Game Account Authentication Service** - Your passport to enter the gaming world

๐Ÿ›๏ธ Part of the go-pantheon ecosystem ๐Ÿ›๏ธ

About

A specialized game account authentication service with dual-token architecture and multi-platform login support.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •