Sign in with Google (OAuth code)
curl --request GET \
--url http://localhost:2000/auth/signin/google/{code}import requests
url = "http://localhost:2000/auth/signin/google/{code}"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('http://localhost:2000/auth/signin/google/{code}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "2000",
CURLOPT_URL => "http://localhost:2000/auth/signin/google/{code}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "http://localhost:2000/auth/signin/google/{code}"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("http://localhost:2000/auth/signin/google/{code}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:2000/auth/signin/google/{code}")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"token": "<string>",
"user": {
"_id": "<string>",
"emails": "user@example.com",
"role": "user"
}
}OAuth & Sessions
Google OAuth Sign-in
Exchange Google OAuth authorization code for user profile and issue a session token. If the user does not exist, a new user is created.
GET
/
auth
/
signin
/
google
/
{code}
Sign in with Google (OAuth code)
curl --request GET \
--url http://localhost:2000/auth/signin/google/{code}import requests
url = "http://localhost:2000/auth/signin/google/{code}"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('http://localhost:2000/auth/signin/google/{code}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "2000",
CURLOPT_URL => "http://localhost:2000/auth/signin/google/{code}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "http://localhost:2000/auth/signin/google/{code}"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("http://localhost:2000/auth/signin/google/{code}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:2000/auth/signin/google/{code}")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"token": "<string>",
"user": {
"_id": "<string>",
"emails": "user@example.com",
"role": "user"
}
}Exchange Google OAuth authorization code for user profile and issue a session token. If the user does not exist, a new user is created.
Request
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | Authorization code returned by Google’s OAuth flow |
Response
200 OK - Successful sign-in
Returns user and token.{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"_id": "64b7f1a2e4b0a5d3f9c12345",
"emails": "user@example.com",
"role": "user"
}
}
400 Bad Request
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid authorization code"
}
}
500 Internal Server Error
{
"error": {
"code": "SERVER_ERROR",
"message": "Internal server error"
}
}
Example
curl -X GET 'http://localhost:2000/auth/signin/google/4/0AX4XfWj...'
Notes
- The authorization code must be obtained from Google’s OAuth 2.0 flow
- If the user doesn’t exist in the system, a new user account will be created
- The returned token should be stored securely and used for subsequent authenticated requests
- Token expiration time is typically 24 hours
OAuth Flow
- Redirect user to Google’s OAuth consent screen
- User authorizes the application
- Google redirects back with authorization code
- Exchange the code for access token and user profile using this endpoint
Was this page helpful?