Search by

ashvia / sdk

alvipan

Official PHP SDK for the ASHVIA Ecosystem.

Package info

github.com/alvipan/via-sdk

pkg:composer/ashvia/sdk

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.3 2026-07-22 05:40 UTC

This package is auto-updated.

Last update: 2026-10-14 17:22:07 UTC


README

Official PHP SDK for the ASHVIA ecosystem.

Installation

composer require ashvia/sdk

For local development:

composer install

Configuration

You can configure the SDK using the builder or by creating a Config instance.

Builder

use Ashvia\Sdk\Ashvia;

$sdk = Ashvia::builder()
    ->baseUrl('https://passport.example.test')
    ->clientId('client-id')
    ->clientSecret('client-secret')
    ->redirectUri('https://app.example.test/callback')
    ->build();

Config

use Ashvia\Sdk\Ashvia;
use Ashvia\Sdk\Config;

$config = new Config(
    baseUrl: 'https://passport.example.test',
    clientId: 'client-id',
    clientSecret: 'client-secret',
    redirectUri: 'https://app.example.test/callback',
);

$sdk = new Ashvia(config: $config);

Authentication

Login

Generate the login URL and redirect the user.

return redirect(
    $sdk->auth()->loginUrl('state-123')
);

authorizationUrl() is still available for backward compatibility.

return redirect(
    $sdk->auth()->authorizationUrl('state-123')
);

Register

Generate the registration URL.

return redirect(
    $sdk->account()->registerUrl('state-123')
);

Forgot Password

Generate the forgot password URL.

return redirect(
    $sdk->account()->forgotPasswordUrl('state-123')
);

OAuth

Exchange Authorization Code

$token = $sdk->auth()->token($code);

echo $token->accessToken();

Refresh Token

$token = $sdk->auth()->refresh($refreshToken);

Revoke Token

$sdk->auth()->revoke($token->accessToken());

User

Retrieve the authenticated user.

$response = $sdk->user()->current(
    $token->accessToken()
);

$user = $response->json();

print_r($user);

Complete Example

use Ashvia\Sdk\Ashvia;

$sdk = Ashvia::builder()
    ->baseUrl('https://passport.example.test')
    ->clientId('client-id')
    ->clientSecret('client-secret')
    ->redirectUri('https://app.example.test/callback')
    ->build();

// Redirect user to login
return redirect(
    $sdk->auth()->loginUrl()
);

// Callback
$token = $sdk->auth()->token(request('code'));

$user = $sdk->user()->current(
    $token->accessToken()
);

print_r($user->json());

License

Released under the MIT License.