OAuth Integration
Byg sikre integrationer med Shoporama API ved hjælp af OAuth 2.0
Hvad er OAuth?
OAuth gør det muligt for eksterne applikationer at få sikker adgang til Shoporama API'et på vegne af dine brugere, uden at de skal dele deres login-oplysninger.
Safe and secure
Ingen deling af passwords. Brugerne logger ind direkte hos Shoporama
Nem integration
Standard OAuth 2.0 flow som du kender fra andre tjenester
Fleksibel
Vælg præcist hvilke rettigheder din app skal have
OAuth Flow - Trin for trin
Send bruger til Shoporama
Your app sends the user to Shoporama's OAuth endpoint
https://www.shoporama.dk/admin/oauth/login?
client_id=Din_App_Navn
redirect_uri=https://example.com/callback
state=unik_session_id
User logs in
The user logs in with their Shoporama credentials and selects:
- Which shop to give access to
- Access level (read, write or full access)
Receive API token
After authentication, the user is sent back to your app with the token:
https://example.com/callback?
token=6b3dd0624ca600c5bbbb...
shop_url=demo.shoporama.dk
shop_name=Demo Shop
api_endpoint=https://www.shoporama.dk/REST
webshop_id=1
access_level=all
state=unik_session_id
Use the API
Use the token to call the Shoporama API:
curl -H "Authorization: 6b3dd0624ca600c5bbbb..." \
https://www.shoporama.dk/REST/product
Klar til at komme i gang?
Start by testing the OAuth flow or read more about the API
Komplette Implementeringseksempler
Fuld OAuth flow implementation - klar til copy/paste
Vanilla PHP Implementation
Ren PHP uden frameworks - en enkelt fil der håndterer hele OAuth flowet
<?php
// oauth.php - Gem denne fil på din server
session_start();
// Konfiguration - RET DISSE VÆRDIER
$CLIENT_ID = "Dit App Navn";
$REDIRECT_URI = "https://din-side.dk/oauth.php";
$OAUTH_URL = "https://www.shoporama.dk/admin/oauth/login";
// Start OAuth
if (isset($_GET["login"])) {
$_SESSION["state"] = bin2hex(random_bytes(16));
$url = $OAUTH_URL . "?" . http_build_query([
"client_id" => $CLIENT_ID,
"redirect_uri" => $REDIRECT_URI,
"state" => $_SESSION["state"]
]);
header("Location: $url");
exit;
}
// Modtag token
if (isset($_GET["token"]) && $_GET["state"] === $_SESSION["state"]) {
$_SESSION["token"] = $_GET["token"];
$_SESSION["api_url"] = $_GET["api_endpoint"];
echo "Success! Token gemt.";
echo "
Test API";
exit;
}
// Test API
if (isset($_GET["test"]) && isset($_SESSION["token"])) {
$ch = curl_init($_SESSION["api_url"] . "/product?limit=1");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: " . $_SESSION["token"]]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "" . htmlspecialchars($result) . "
";
exit;
}
// Start side
echo "Login med Shoporama";
?>
Sådan bruger du det:
- Kopier koden til en fil kaldet
oauth.php
- Ret
$CLIENT_ID
og$REDIRECT_URI
- Upload filen til din server
- Besøg siden og klik "Login med Shoporama"
Troubleshooting & Common issues
Common OAuth errors
access_denied
The user was denied access. Show a friendly message and let them try again.
invalid_client
Unknown client_id. Check that your app name is correct.
invalid_redirect_uri
Redirect URI does not match. Must be the exact same URL.
state_mismatch
State parameter does not match. Possible CSRF attack or session timeout.
API errors
401 Unauthorized
Token is invalid or expired. Ask the user to log in again.
403 Forbidden
Token does not have the necessary rights. Check access_level.
429 Too Many Requests
Rate limit reached. Please wait until the next request.
500 Server Error
Internal error. Please try again later or contact support.
Debug tips
Test with OAuth Test Client
Use our test client to verify your OAuth flow is working correctly.
Test OAuth Flow →Log all parameters
Log state, token and other parameters to debug issues.
Safety & Best Practices
Token storage
- • Never store tokens in cookies or localStorage
- • Use server-side sessions or encrypted database
- • Encrypt tokens before storage
- • Delete tokens when they are no longer used
CSRF protection
- • Always use state parameter
- • Generate unique state for each session
- • Verify state in callback
- • Timeout state after a short time
HTTPS required
- • Only use HTTPS for redirect_uri
- • All API calls must be over HTTPS
- • Exception: localhost for development
- • Check SSL certificate validity
Access levels explained
Level | Description | Allowed | Not allowed |
---|---|---|---|
read | Read access to all data | GET requests to all endpoints | POST, PUT, DELETE requests |
write | Read and write data | All HTTP methods | Delete webshop, change ownership |
all | Full administrator access | Everything including dangerous operations | Nothing - full control |
Recommendation: Start with 'read' access during development and only upgrade to 'write' or 'all' when necessary for your application's functionality.
Complete API documentation
See all available endpoints, methods and parameters in our REST API documentation
See API Documentation