> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.vlenseg.com/llms.txt.
> For full documentation content, see https://docs.vlenseg.com/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.vlenseg.com/_mcp/server.

# Create an embedded auth session

POST https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession
Content-Type: application/json

Create a session token for a user identified by phone number or email. This token is used to launch the Vlens iframe or WebView for that user, embedding the full verification and contracting UX inside your own application.

**Authentication:** Requires only the `ApiKey` header — no admin bearer token.


Reference: https://docs.vlenseg.com/api-reference/vlens-api/identity-user-session/create-auth-session

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: example-openapi
  version: 1.0.0
paths:
  /api/IdentityUserSession/CreateAuthSession:
    post:
      operationId: create-auth-session
      summary: Create an embedded auth session
      description: >
        Create a session token for a user identified by phone number or email.
        This token is used to launch the Vlens iframe or WebView for that user,
        embedding the full verification and contracting UX inside your own
        application.


        **Authentication:** Requires only the `ApiKey` header — no admin bearer
        token.
      tags:
        - subpackage_identityUserSession
      parameters:
        - name: ApiKey
          in: header
          description: >-
            Static API key issued to your tenant. Obtain from the Vlens
            dashboard.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Session token. Use this to initialize the Vlens iframe.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiOutputString'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAuthSessionInput'
servers:
  - url: https://api.vlenseg.com
components:
  schemas:
    SessionPermissions:
      type: object
      properties:
        allowedContractTypeIds:
          type: array
          items:
            type: integer
          description: Contract type IDs the user may create in this session.
        minimalSignatureFlow:
          type: boolean
          description: Skip optional steps and use the streamlined signing flow.
        DigitalIdentityOnly:
          type: boolean
          description: If `true`, the session only performs KYC — no contract creation.
      description: Controls which features and contract types are available in the session.
      title: SessionPermissions
    CreateAuthSessionInput:
      type: object
      properties:
        phoneNumber:
          type:
            - string
            - 'null'
        email:
          type:
            - string
            - 'null'
          format: email
        userPublicKey:
          type:
            - string
            - 'null'
          description: Optional RSA public key to encrypt the session token.
        sessionPermissions:
          $ref: '#/components/schemas/SessionPermissions'
      description: >-
        Creates a session token for a user. Used for iframe and WebView
        integrations.
      title: CreateAuthSessionInput
    ApiOutputString:
      type: object
      properties:
        data:
          type:
            - string
            - 'null'
        error_code:
          type:
            - integer
            - 'null'
        error_message:
          type:
            - string
            - 'null'
        error_descriptions:
          oneOf:
            - description: Any type
            - type: 'null'
      title: ApiOutputString
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: ApiKey
      description: Static API key issued to your tenant. Obtain from the Vlens dashboard.

```

## SDK Code Examples

```python Identity User Session_createAuthSession_example
import requests

url = "https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession"

payload = {
    "phoneNumber": "+201234567890",
    "sessionPermissions": {
        "allowedContractTypeIds": [414],
        "minimalSignatureFlow": True,
        "DigitalIdentityOnly": False
    }
}
headers = {
    "ApiKey": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Identity User Session_createAuthSession_example
const url = 'https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession';
const options = {
  method: 'POST',
  headers: {ApiKey: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"phoneNumber":"+201234567890","sessionPermissions":{"allowedContractTypeIds":[414],"minimalSignatureFlow":true,"DigitalIdentityOnly":false}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Identity User Session_createAuthSession_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession"

	payload := strings.NewReader("{\n  \"phoneNumber\": \"+201234567890\",\n  \"sessionPermissions\": {\n    \"allowedContractTypeIds\": [\n      414\n    ],\n    \"minimalSignatureFlow\": true,\n    \"DigitalIdentityOnly\": false\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("ApiKey", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Identity User Session_createAuthSession_example
require 'uri'
require 'net/http'

url = URI("https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["ApiKey"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"phoneNumber\": \"+201234567890\",\n  \"sessionPermissions\": {\n    \"allowedContractTypeIds\": [\n      414\n    ],\n    \"minimalSignatureFlow\": true,\n    \"DigitalIdentityOnly\": false\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Identity User Session_createAuthSession_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession")
  .header("ApiKey", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phoneNumber\": \"+201234567890\",\n  \"sessionPermissions\": {\n    \"allowedContractTypeIds\": [\n      414\n    ],\n    \"minimalSignatureFlow\": true,\n    \"DigitalIdentityOnly\": false\n  }\n}")
  .asString();
```

```php Identity User Session_createAuthSession_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession', [
  'body' => '{
  "phoneNumber": "+201234567890",
  "sessionPermissions": {
    "allowedContractTypeIds": [
      414
    ],
    "minimalSignatureFlow": true,
    "DigitalIdentityOnly": false
  }
}',
  'headers' => [
    'ApiKey' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Identity User Session_createAuthSession_example
using RestSharp;

var client = new RestClient("https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession");
var request = new RestRequest(Method.POST);
request.AddHeader("ApiKey", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phoneNumber\": \"+201234567890\",\n  \"sessionPermissions\": {\n    \"allowedContractTypeIds\": [\n      414\n    ],\n    \"minimalSignatureFlow\": true,\n    \"DigitalIdentityOnly\": false\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Identity User Session_createAuthSession_example
import Foundation

let headers = [
  "ApiKey": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "phoneNumber": "+201234567890",
  "sessionPermissions": [
    "allowedContractTypeIds": [414],
    "minimalSignatureFlow": true,
    "DigitalIdentityOnly": false
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.vlenseg.com/api/IdentityUserSession/CreateAuthSession")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```