Create Auth Session
curl --request POST \
--url https://api.example.com/v1/identity/sessions \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"provider": "<string>"
}
'import requests
url = "https://api.example.com/v1/identity/sessions"
payload = {
"user_id": "<string>",
"provider": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', provider: '<string>'})
};
fetch('https://api.example.com/v1/identity/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/identity/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'user_id' => '<string>',
'provider' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/identity/sessions"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/identity/sessions")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/identity/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"session_id": "<string>",
"auth_url": "<string>",
"expires_at": "<string>"
}Identity
Create Auth Session
Create a JIT authentication session for OAuth
POST
/
v1
/
identity
/
sessions
Create Auth Session
curl --request POST \
--url https://api.example.com/v1/identity/sessions \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"provider": "<string>"
}
'import requests
url = "https://api.example.com/v1/identity/sessions"
payload = {
"user_id": "<string>",
"provider": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', provider: '<string>'})
};
fetch('https://api.example.com/v1/identity/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/identity/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'user_id' => '<string>',
'provider' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/identity/sessions"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/identity/sessions")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/identity/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"provider\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"session_id": "<string>",
"auth_url": "<string>",
"expires_at": "<string>"
}Create Auth Session
Create a just-in-time (JIT) authentication session. This returns a URL to redirect the user to for OAuth authorization.Request
curl -X POST https://api.mcprank.com/v1/identity/sessions \
-H "X-API-Key: sk_mcp_rank_..." \
-H "Content-Type: application/json" \
-d '{
"user_id": "user_123",
"provider": "google"
}'
Body Parameters
string
required
Your user’s unique identifier
string
required
OAuth provider to authenticate with. Currently supported:
googleResponse
string
Unique identifier for this auth session - use for polling status
string
URL to redirect the user to for OAuth authorization
string
ISO timestamp when this session expires (typically 5 minutes)
Example Response
{
"session_id": "sess_abc123",
"auth_url": "https://accounts.google.com/o/oauth2/v2/auth?client_id=...&redirect_uri=...&scope=...",
"expires_at": "2024-01-15T10:05:00Z"
}
Flow
- Call this endpoint to get an
auth_url - Redirect user to
auth_url(or open in popup/new tab) - User authorizes in Google
- Google redirects to MCP Rank’s callback
- MCP Rank stores tokens server-side
- Poll
/v1/identity/sessions/{session_id}for completion - Once complete, proxy requests will work
Example Flow
# 1. Create session
session = await client.create_auth_session("google")
# 2. Show URL to user
print(f"Please open: {session['auth_url']}")
# 3. Poll for completion
import asyncio
while True:
status = await client.check_session_status(session["session_id"])
if status["status"] == "complete":
print("Success!")
break
elif status["status"] == "error":
raise Exception(f"Auth failed: {status['error']}")
await asyncio.sleep(1)
# 4. Refresh client and make requests
await client.initialize()
profile = await client.proxy_get("google", "gmail/v1/users/me/profile")
Notes
- Sessions expire after 5 minutes
- After successful auth, tokens are stored server-side (KMS encrypted)
- The same
user_idcan have multiple providers connected