Skip to main content

Login with Paysera

Paysera offers a secure API that lets your customers sign in to your website using their Paysera account. Quick, fast, and convenient way for people to log into your website.

OAuth 2.0 Integration

This use case implements OAuth 2.0 authorization code flow for secure user authentication.

Use Cases

Registration: Let people quickly create an account without setting a password or filling registration forms. Obtain user data confirmed by Paysera system.

Login: Let people sign in with the same data they use in Paysera. No need to save user data in your system.


Benefits

  • Real Identity - When people log in with Paysera, they share their real identity - name, gender, locale, phone
  • Automatic Updates - Get up-to-date customer data from Paysera, which is renewed automatically
  • Permission Control - Allow users to control what info they share

OAuth Flow


Integration Steps

Step 1: Redirect to Authorization

Redirect user to: https://www.paysera.com/frontend/oauth

Required parameters: response_type=code, client_id, redirect_uri, scope

Example URL:

https://www.paysera.com/frontend/oauth?
response_type=code&
client_id=wkVd93h2uS&
redirect_uri=https://yoursite.com/callback&
scope=email+name&
state=random_string

Step 2: Handle Callback

User is redirected back with authorization code:

https://yoursite.com/callback?code=AUTHORIZATION_CODE&state=random_string

Step 3: Exchange Code for Token

Make POST request to: https://wallet.paysera.com/oauth/v1/token

Step 4: Get User Information

Use access token: GET https://wallet.paysera.com/rest/v1/user/me


Implementation Examples

<?php
require_once 'vendor/autoload.php';

use Paysera\WalletApi\ClientFactory;
use Paysera\WalletApi\OAuth\Consumer;

session_start();

// Configuration
$clientId = 'wkVd93h2uS';
$secret = 'IrdTc8uQodU7PRpLzzLTW6wqZAO6tAMU';

// Create API client
$api = ClientFactory::create([
'auth' => [
'mac' => [
'mac_id' => $clientId,
'mac_secret' => $secret,
],
],
]);

$oauth = $api->oauthConsumer();

try {
// Check if we have token
if (!isset($_SESSION['token'])) {
// Try to get token from callback
$token = $oauth->getOAuthAccessToken();

if ($token === null) {
// No token yet, redirect to authorization
$scopes = [
Consumer::SCOPE_EMAIL,
Consumer::SCOPE_PHONE,
Consumer::SCOPE_FULL_NAME,
];

$authUrl = $oauth->getAuthorizationUri($scopes, null);
header('Location: ' . $authUrl);
exit;
} else {
// Got token from callback
$_SESSION['token'] = $token;
}
}

// We have token, get user info
if (isset($_SESSION['token'])) {
$client = $api->walletClientWithToken($_SESSION['token']);
$user = $client->getUser();

// User data
$userId = $user->getId();
$email = $user->getEmail();
$name = $user->getDisplayName();
$phone = $user->getPhone();

// Update token (might be refreshed)
$_SESSION['token'] = $client->getCurrentAccessToken();

// Use user data for login/registration
echo "Welcome, $name!";
echo "<br>Email: $email";
echo "<br>User ID: $userId";
}

} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}

Advanced Topics

Available Scopes
ScopeDescription
emailUser's email address
phoneUser's phone number
full_nameUser's full name
identityPersonal identity information
addressUser's address
balanceWallet balance (requires additional permissions)
statementsTransaction history (requires additional permissions)
Security Best Practices

Do:

  • ✅ Validate state parameter to prevent CSRF attacks
  • ✅ Store MAC secret securely (environment variables)
  • ✅ Use HTTPS for all redirects
  • ✅ Implement token refresh logic
  • ✅ Handle errors gracefully

Don't:

  • ❌ Don't expose MAC secret in client-side code
  • ❌ Don't skip state parameter validation
  • ❌ Don't store tokens in localStorage (use secure cookies)
  • ❌ Don't ignore token expiration
Testing

Production Testing:

$api = ClientFactory::create([
'auth' => ['mac' => [
'mac_id' => 'your_client_id',
'mac_secret' => 'your_secret',
]],
'base_url' => 'https://wallet.paysera.com/rest/v1/',
]);
Production Environment

OAuth testing is done in production. Test thoroughly with real accounts before full deployment.

Troubleshooting

Redirect URI mismatch

  • Ensure redirect_uri matches exactly in both authorization and token requests
  • Check if URI is registered in Paysera system

Invalid grant

  • Authorization code can only be used once
  • Code expires after 10 minutes

Token expired

  • Implement token refresh logic
  • Request new authorization if refresh fails

Resources


Next Steps

After implementing Login with Paysera:

  • Add user profile management
  • Implement session handling
  • Set up user database
  • Add logout functionality
Production Ready

Test thoroughly before full deployment to ensure OAuth flow works correctly!