141 lines
4.6 KiB
PHP
141 lines
4.6 KiB
PHP
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>{!! $metadata['title'] !!}</title>
|
|
<meta charset="utf-8"/>
|
|
<meta
|
|
name="viewport"
|
|
content="width=device-width, initial-scale=1"/>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
}
|
|
#token-manager {
|
|
position: fixed;
|
|
bottom: 20px;
|
|
right: 20px;
|
|
z-index: 99999;
|
|
background: #1e1e20;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
|
|
font-family: sans-serif;
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
border: 1px solid #333;
|
|
}
|
|
#token-manager input {
|
|
padding: 8px;
|
|
border-radius: 4px;
|
|
border: 1px solid #444;
|
|
background: #2d2d30;
|
|
color: #fff;
|
|
width: 250px;
|
|
outline: none;
|
|
}
|
|
#token-manager button {
|
|
padding: 8px 15px;
|
|
border-radius: 4px;
|
|
border: none;
|
|
background: #6c5ce7;
|
|
color: white;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
}
|
|
#token-manager button:hover {
|
|
background: #5b4cc4;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Token Manager UI -->
|
|
<div id="token-manager">
|
|
<input type="text" id="manual-token-input" placeholder="Paste your Bearer Token here...">
|
|
<button onclick="saveManualToken()">Save & Reload</button>
|
|
</div>
|
|
|
|
<script>
|
|
function saveManualToken() {
|
|
const token = document.getElementById('manual-token-input').value.trim();
|
|
if(token) {
|
|
localStorage.setItem('token', token);
|
|
// Also ensure configuration is updated before reload (optional but good for consistency)
|
|
alert('Token saved to localStorage! The page will reload.');
|
|
window.location.reload();
|
|
} else {
|
|
localStorage.removeItem('token');
|
|
alert('Token removed from localStorage!');
|
|
window.location.reload();
|
|
}
|
|
}
|
|
|
|
// Load existing token into input for visibility
|
|
// Run immediately to avoid flash if possible, or on load
|
|
window.addEventListener('load', function() {
|
|
const token = localStorage.getItem('token') || localStorage.getItem('access_token');
|
|
if(token) {
|
|
const input = document.getElementById('manual-token-input');
|
|
if(input) input.value = token;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script
|
|
id="api-reference"
|
|
@foreach($htmlAttributes as $attribute => $value)
|
|
{{-- Attributes specified first override later ones --}}
|
|
{!! $attribute !!}="{!! $value !!}"
|
|
@endforeach
|
|
data-url="{!! $metadata['openapi_spec_url'] !!}">
|
|
</script>
|
|
|
|
<script>
|
|
// Auto-fill auth token from localStorage for Scribe/Scalar
|
|
// Runs immediately after the element is defined but before Scalar loads
|
|
(function() {
|
|
try {
|
|
const token = localStorage.getItem('token') || localStorage.getItem('access_token') || localStorage.getItem('auth_token');
|
|
|
|
if (token) {
|
|
const referenceElement = document.getElementById('api-reference');
|
|
if (referenceElement) {
|
|
// Prepare Scalar configuration
|
|
const config = {
|
|
authentication: {
|
|
preferredSecurityScheme: 'default',
|
|
http: {
|
|
bearer: {
|
|
token: token
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// Merge with existing configuration
|
|
let existingConfig = {};
|
|
try {
|
|
if (referenceElement.dataset.configuration) {
|
|
existingConfig = JSON.parse(referenceElement.dataset.configuration);
|
|
}
|
|
} catch (e) {
|
|
console.error('Error parsing Scalar config:', e);
|
|
}
|
|
|
|
const newConfig = { ...existingConfig, ...config };
|
|
|
|
// Update the attribute synchronously before Scalar script loads
|
|
referenceElement.dataset.configuration = JSON.stringify(newConfig);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Error auto-filling token:', e);
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
</body>
|
|
</html>
|