Skip to content

kaktaknet/discourse-vkid-oauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” VK ID Authentication for Discourse

Discourse Ruby JavaScript OAuth 2.1 License

🌍 Languages / Π―Π·Ρ‹ΠΊΠΈ

English Русский


OAuth 2.1 authentication plugin with VK ID, OK.ru, and Mail.ru support

Features β€’ Installation β€’ Configuration β€’ Migration β€’ Documentation


πŸ†• What's New in Version 2.0

Complete rewrite for VK ID (id.vk.ru):

Feature Status
πŸ”’ OAuth 2.1 with mandatory PKCE βœ…
πŸ†” VK ID endpoints (id.vk.ru) βœ…
🎨 OneTap widget (VK ID SDK) βœ…
πŸ”„ Automatic user migration βœ…
🌐 Multi-provider (VK/OK/Mail.ru) βœ…
πŸ“± Mobile responsive βœ…
πŸŒ™ Dark theme support βœ…
πŸ§ͺ Test coverage (~150 tests) βœ…
πŸ“– Bilingual docs (EN/RU) βœ…

⚑ Features

πŸ” Security

  • OAuth 2.1 with PKCE
  • Authorization code interception protection
  • Email verification via id_token
  • No permanent token storage
  • Comprehensive error handling

🎨 User Experience

  • OneTap widget in login modal
  • Multi-provider support:
    • πŸ”΅ VK ID
    • 🟠 OK.ru
    • πŸ”΅ Mail.ru
  • One-click authentication
  • Auto-migration from old provider

πŸ› οΈ Developer Tools

  • Custom OmniAuth strategy
  • Rake migration tasks
  • Comprehensive test suite
  • Detailed logging
  • TypeScript-ready

πŸ“š Documentation

  • Complete setup guide
  • Migration documentation
  • API reference
  • Troubleshooting guide
  • Code examples

πŸ“‹ Requirements

Component Version
Discourse 2.7.0 or higher
Ruby 2.7+
VK ID Application registered at id.vk.ru
VK ID Demo VK ID demo at id.vk.ru

πŸš€ Installation

Step 1: Install Plugin

Follow the Install a Plugin guide using:

cd /var/discourse
nano containers/app.yml

Add to hooks.after_code:

- git clone https://github.com/kaktaknet/discourse-vkid-oauth.git
git@github.com:kaktaknet/discourse-vkid-oauth.git

Step 2: Rebuild Container

cd /var/discourse
./launcher rebuild app

βš™οΈ Configuration

1. Create VK ID Application

  1. Go to VK ID Console
  2. Click "Create Application"
  3. Choose "Website" platform

2. Configure OAuth

Redirect URI:

https://your-discourse-site.com/auth/vkid/callback

Scopes:

  • βœ… vkid.personal_info (required)
  • βœ… email (recommended)
  • βœ… phone (optional)

PKCE: βœ… Must be enabled

3. Discourse Settings

Navigate to: Admin β†’ Settings β†’ Login

Setting Value Description
vkid_enabled βœ… Enable VK ID authentication
vkid_client_id 123456 App ID from VK ID console
vkid_client_secret β€’β€’β€’β€’β€’β€’ Secret key from VK ID
vkid_scope vkid.personal_info email phone OAuth scopes
vkid_widget_enabled βœ… Enable OneTap widget
vkid_widget_providers vkid,ok_ru,mail_ru Widget providers

🎨 OneTap Widget

Modern UI with Multi-Provider Support

Provider Color Icon
VK ID #0077ff πŸ”΅
OK.ru #ee8208 🟠
Mail.ru #005ff9 πŸ”΅

Features:

  • ⚑ Loads asynchronously (~50KB gzipped)
  • πŸ“± Mobile responsive design
  • πŸŒ™ Dark theme support
  • 🎯 One-click authentication
  • πŸ”„ Seamless backend integration

πŸ”„ Migration from Old Plugin

Automatic Migration ✨

Users are automatically migrated on first login:

User logs in with VK ID
    ↓
Plugin detects old 'vkontakte' account
    ↓
Updates to 'vkid' provider
    ↓
User logged in seamlessly βœ…

No manual intervention required!

Manual Migration (Optional)

Migrate all users at once:

cd /var/discourse
./launcher enter app
rake vkid:migrate_users

See: MIGRATION_GUIDE.md for detailed instructions


πŸ—οΈ Architecture

OAuth 2.1 Flow with PKCE

graph LR
    A[User] -->|Click Login| B[VK ID Widget]
    B -->|Generate PKCE| C[VK ID Server]
    C -->|Authorization Code| D[Discourse Callback]
    D -->|Exchange + Verify PKCE| E[Access Token]
    E -->|Fetch User Info| F[Create/Update User]
    F -->|Session| A
Loading

Technology Stack

Layer Technology Purpose
Frontend JavaScript VK ID SDK Widget UI
Backend Ruby Custom Strategy OAuth 2.1 + PKCE
Auth OAuth Secure flow
Data PostgreSQL User storage

Files Structure

discourse-vk-auth/
β”œβ”€β”€ πŸ“„ plugin.rb                              # Entry point
β”œβ”€β”€ πŸ“ lib/
β”‚   β”œβ”€β”€ πŸ” vkid_authenticator.rb             # Main authenticator
β”‚   β”œβ”€β”€ πŸ”‘ omniauth/strategies/vkid.rb       # OAuth 2.1 + PKCE
β”‚   └── πŸ› οΈ tasks/vkid_migration.rake         # Migration utilities
β”œβ”€β”€ πŸ“ assets/
β”‚   β”œβ”€β”€ 🎨 javascripts/                       # VK ID widget
β”‚   └── πŸ’… stylesheets/                       # Widget styles
β”œβ”€β”€ πŸ“ config/
β”‚   β”œβ”€β”€ βš™οΈ settings.yml                       # Plugin settings
β”‚   └── 🌐 locales/                           # i18n (en, ru)
β”œβ”€β”€ πŸ§ͺ spec/                                  # Test suite (~150 tests)
β”œβ”€β”€ πŸ“– README.md                              # This file
β”œβ”€β”€ πŸ“– README_RU.md                           # Russian docs
β”œβ”€β”€ πŸ“– MIGRATION_GUIDE.md                     # Migration guide
└── πŸ“– MIGRATION_GUIDE_RU.md                  # Russian migration

πŸ§ͺ Testing

Run the test suite:

bundle exec rspec

Coverage:

  • βœ… PKCE generation and validation
  • βœ… User migration scenarios
  • βœ… Username uniqueness
  • βœ… Error handling
  • βœ… ID Token parsing
  • βœ… OAuth flow integration

Total: ~150 test cases


πŸ› Troubleshooting

❌ "invalid_request: code_verifier is missing"

Cause: PKCE not properly implemented or disabled.

Solution: Ensure you're using plugin v2.0+. PKCE is handled automatically by the custom strategy.

❌ "No email returned from VK ID"

Cause: Email scope not granted or user hasn't provided email.

Solution:

  • Check vkid_scope includes email
  • Verify VK ID app has email permission enabled
  • User must have email in their VK account
❌ "redirect_uri_mismatch"

Cause: Redirect URI doesn't match VK app settings.

Solution: Verify redirect URI in VK ID console:

https://your-site.com/auth/vkid/callback
❌ Widget not showing

Checks:

  1. vkid_enabled is true
  2. vkid_widget_enabled is true
  3. vkid_client_id is configured
  4. Browser console for errors

Debug:

console.log(window.VKIDSDK); // Should show SDK
console.log(Discourse.SiteSettings.vkid_enabled); // true

See: Full troubleshooting guide in README.md


πŸ“š Documentation

Document Description
πŸ“– README.md Main documentation (English)
πŸ“– README_RU.md ДокумСнтация (Русский)
πŸ“– MIGRATION_GUIDE.md Migration from v1.x
πŸ“– MIGRATION_GUIDE_RU.md Руководство ΠΏΠΎ ΠΌΠΈΠ³Ρ€Π°Ρ†ΠΈΠΈ

πŸ”— API Endpoints

Endpoint Purpose
https://id.vk.ru/authorize OAuth authorization
https://id.vk.ru/oauth2/auth Token exchange
https://id.vk.ru/oauth2/user_info User information

🀝 Support


πŸ“„ License

MIT License - see LICENSE file for details


πŸŽ‰ Changelog

Version 2.0.0 (2025)

✨ New Features

  • βœ… OAuth 2.1 with mandatory PKCE
  • βœ… Custom OmniAuth strategy
  • βœ… VK ID SDK widget integration
  • βœ… Multi-provider support (VK/OK/Mail.ru)
  • βœ… Automatic user migration
  • βœ… Bilingual documentation

πŸ”§ Technical

  • βœ… New endpoints (id.vk.ru)
  • βœ… PKCE implementation (RFC 7636)
  • βœ… ID Token parsing
  • βœ… Enhanced security
  • βœ… Comprehensive tests

πŸ“– Documentation

  • βœ… Complete rewrite
  • βœ… Migration guides
  • βœ… Widget documentation
  • βœ… Troubleshooting

Version 1.x (Legacy - Deprecated)

  • ⚠️ Old VK OAuth 2.0 (oauth.vk.com)
  • ⚠️ No PKCE support
  • ⚠️ No longer compatible

**Made with ❀️ for Discourse community**

⬆ Back to top

About

πŸ” VK ID Authentication for Discourse. OAuth 2.1 authentication plugin with VK ID, OK.ru, and Mail.ru support.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors