Odnoklassniki Authentication for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Odnoklassniki OAuth Authentication Implementation for Websites

Odnoklassniki is part of VK Group. Auth via OK is relevant for 35+ audience, especially in Russia and CIS regions. Implemented via OAuth2 with specifics in request signing for OK API.

Registering Application

  1. ok.ru/dk?st.cmd=appcenter (or developer section)
  2. Create external application
  3. Specify site address and allowed redirect URIs
  4. Get: App ID, Public key, Secret key

Laravel Socialite

composer require laravel/socialite socialiteproviders/odnoklassniki
// config/services.php
'odnoklassniki' => [
    'client_id'     => env('OK_APP_ID'),
    'client_secret' => env('OK_SECRET_KEY'),
    'client_public' => env('OK_PUBLIC_KEY'),
    'redirect'      => env('OK_REDIRECT_URI'),
],

class OkAuthController extends Controller
{
    public function redirect(): RedirectResponse
    {
        return Socialite::driver('odnoklassniki')
            ->scopes(['VALUABLE_ACCESS', 'GET_EMAIL'])
            ->redirect();
    }

    public function callback(): RedirectResponse
    {
        try {
            $okUser = Socialite::driver('odnoklassniki')->user();
        } catch (\Exception $e) {
            return redirect('/login')->withErrors(['ok' => 'Odnoklassniki authorization error']);
        }

        $user = User::updateOrCreate(
            ['ok_id' => $okUser->getId()],
            [
                'name'   => $okUser->getName(),
                'email'  => $okUser->getEmail() ?: null,
                'avatar' => $okUser->getAvatar(),
            ]
        );

        Auth::login($user, remember: true);
        return redirect()->intended('/dashboard');
    }
}

Signing OK API Requests

OK API has specifics: requests are signed with MD5 hash of parameters + session_secret_key. Socialite provider handles this automatically, but for direct API calls account for:

function signOkRequest(array $params, string $accessToken, string $secretKey): string
{
    ksort($params);
    $paramString = '';
    foreach ($params as $key => $value) {
        $paramString .= "{$key}={$value}";
    }

    // session_secret_key = MD5(access_token + secret_key)
    $sessionSecretKey = md5($accessToken . $secretKey);

    return md5($paramString . $sessionSecretKey);
}

Available Data

Field Availability
UID (unique ID) Always
Name and surname Always
Avatar Always
Email Requires scope GET_EMAIL, may be absent
Date of birth Via additional request to users.getInfo
City Via additional request

Timeline

1–2 days.