---
title: "PHP, Python, .NET or Node.js: link users"
description: "Link the users your app already has to Block-Auth."
url: "/sdk-integration-server-extras/"
language: "en"
guide: "PHP, Python, .NET, Node.js"
step: "More options, optional"
---

# Link users

Optional. For apps that already have their own users.

## Link existing users

If your app already has its own users, they can link their Block-Auth identity to their account. After that, signing in with Block-Auth returns their id in your app as `externalId`, so you can sign them in as **your** user.

1. From a page where your user is signed in with your own login (and recently, for example in the last 10 minutes), send them to `/blockauth/login` and remember in the session that it is a link.
2. In the callback, if it is a link, pass your user id as `linkExternalId` when you redeem the code, and keep the user's current session:

**Node.js · server.js · where you create your Express app**

```javascript
const user = await blockauth.exchangeCode(code, CALLBACK_URL, undefined, String(req.session.appUser.id))
```

**PHP · public/index.php · your entry point**

```php
$user = $blockauth->exchangeCode($code, $callbackUrl, null, (string) $_SESSION['app_user']['id']);
```

**Python · app.py · where you create your app**

```python
user = blockauth.exchange_code(code, CALLBACK_URL, link_external_id=str(session["app_user"]["id"]))
```

**.NET · Program.cs**

```csharp
var user = await blockauth.ExchangeCodeAsync(code, callbackUrl, linkExternalId: http.Session.GetString("app_user_id"));
```

If that identity or user is already linked, the call fails with `Account already linked` or `External id already linked`. To remove a link from your side, call `revokeLink(externalId)`.
