← डेवलपर एपीआई डेवलपर्स के लिए

Astrina के साथ लॉगिन करें

Astrina is the single sign-on broker for the ecosystem. Configure your social-login providers once in Astrina; every site reuses them — no per-site OAuth apps, no provider SDKs.

How the flow works

चार हॉप्स, और आपकी साइट कभी भी किसी प्रदाता को नहीं छूती

साइट विज़िटर को Astrina पर भेजती है

एक लिंक जिसमें आपका client_id, वापसी पता और एक राज्य मान है।

विज़िटर एक खाता चुनता है

Astrina में सक्षम कोई भी प्रदाता — आपकी ओर कोई OAuth ऐप नहीं।

Astrina एक बार का कोड लौटाता है

कोड आपके कॉलबैक पर वापस आता है और पांच मिनट में समाप्त हो जाता है।

आपका सर्वर इसे एक प्रोफ़ाइल के लिए बदलता है

एक सर्वर-से-सर्वर POST सब, ईमेल, नाम और अवतार लौटाता है।

अनुरोध आरेख दिखाएँ
  Site  ──(1) redirect──▶  astrina.io/auth/authorize.php  ──▶  provider (Google…)
   ▲                                    │                              │
   └──(3) ?code=…&state=… ◀──── astrina.io/auth/cb.php ◀──(2) callback ─┘
   │
   └──(4) POST code ──▶ astrina.io/auth/token.php ──▶ { sub, email, name, avatar }

One-time owner setup (in Astrina admin)

  1. नियंत्रण पैनल में प्रदाताओं को सक्षम करें (स्वामी पहुंच)।
  2. For each provider, create an OAuth app in that provider's console and register exactly this redirect URI:
    Googlehttps://astrina.io/auth/cb.php?provider=google
    Yandexhttps://astrina.io/auth/cb.php?provider=yandex
    Applehttps://astrina.io/auth/cb.php?provider=apple
    Telegram@BotFather → /setdomain → astrina.io
  3. Paste each app's Client ID + Secret (Telegram: bot username + bot token), tick Enabled, Save.
  4. Under Client sites, register each site (name + allowed redirect URLs). Copy the client_id + client_secret shown once.

Per-site integration (3 steps)

  1. Copy sdk.php into the site and set four constants:
    define('ASTRINA_CLIENT_ID',     'astr_xxxxxxxx');
    define('ASTRINA_CLIENT_SECRET', '…');   // server-side only, never in JS
    define('ASTRINA_REDIRECT_URI',  'https://mysite/auth/astrina-callback.php');
    require '/path/to/sdk.php';
  2. Add the buttons anywhere — one "Login with Astrina" button (shows the chooser), or a row of direct provider buttons (a click on Google jumps straight into Google, no chooser page):
    <!-- one button → Astrina chooser -->
    <a class="btn" href="<?= htmlspecialchars(AstrinaID::loginUrl()) ?>">Log in with Astrina</a>
    
    <!-- OR: direct per-provider buttons + the "Secured by Astrina ID" note -->
    <?= AstrinaID::buttonsHtml() ?>
    
    <!-- OR: hand-rolled, straight to one provider -->
    <a href="<?= htmlspecialchars(AstrinaID::loginUrl('google')) ?>">Continue with Google</a>

    buttonsHtml() fetches the providers you enabled in Astrina and renders exactly those, each deep-linked to the provider.

  3. Create the callback page (astrina-callback.php) at the redirect URL:
    require 'config.php';           // defines the constants + sdk.php
    $u = AstrinaID::handleCallback();
    if (!$u) { header('Location: /login?e=1'); exit; }
    // key your local user on ($u['provider'], $u['sub']) — NOT email
    $local = find_or_create_user($u['provider'], $u['sub'], $u['email'], $u['name'], $u['avatar']);
    login($local); header('Location: /'); exit;

That's it — no per-site OAuth apps, no provider SDKs. Adding a new provider later is a one-row change in Astrina; every site gets it automatically.

Notes

sub is a stable, opaque per-identity id. Treat email as informational (Telegram gives none; users can change it).

The token response also carries an id_token (JWT HS256 signed with your client secret) if you prefer to verify locally instead of trusting the JSON.

Codes are single-use and expire in 5 minutes; state is checked both by the SDK and by Astrina.

Plain-text reference: README.md · download sdk.php