Php 浏览器刷新Laravel时丢失SwaggerUI JWT令牌
我用文档记录我的api。 我使用承载JWT进行身份验证。当我创建新端点或对现有端点进行更改时,我需要刷新SwiggerUI页面。然后我必须重新输入令牌。我怎样才能解决这个问题 我试过解决方案,但对我来说也不起作用 这对我不起作用Php 浏览器刷新Laravel时丢失SwaggerUI JWT令牌,php,laravel,swagger,swagger-ui,openapi,Php,Laravel,Swagger,Swagger Ui,Openapi,我用文档记录我的api。 我使用承载JWT进行身份验证。当我创建新端点或对现有端点进行更改时,我需要刷新SwiggerUI页面。然后我必须重新输入令牌。我怎样才能解决这个问题 我试过解决方案,但对我来说也不起作用 这对我不起作用 (function () { const API_KEY = 'ApiKey'; setTimeout(function () { // store the api key in the local storage var originalAuthorize
(function () {
const API_KEY = 'ApiKey';
setTimeout(function () {
// store the api key in the local storage
var originalAuthorize = ui.authActions.authorize;
ui.authActions.authorize = function (payload) {
window.localStorage.setItem(API_KEY, payload.ApiKeyScheme.value);
return originalAuthorize(payload);
};
// if logout is clicked delete the api key in the local storage
var originalLogout = ui.authActions.logout;
ui.authActions.logout = function (payload) {
window.localStorage.removeItem(API_KEY);
return originalLogout(payload);
};
// If token already exists, load it from local storage
const apiKey = window.localStorage.getItem(API_KEY);
if (apiKey) {
window.ui.preauthorizeApiKey('ApiKeyScheme', apiKey);
}
}, 1000);
})();
找到了解决办法。只要把“persistAuthorization:true”放在招摇过市上,我的问题就解决了 供应商\l5 swagger\index.blade.php
const ui = SwaggerUIBundle({
dom_id: '#swagger-ui',
url: "{!! $urlToDocs !!}",
operationsSorter: {!! isset($operationsSorter) ? '"' . $operationsSorter . '"' : 'null' !!},
configUrl: {!! isset($configUrl) ? '"' . $configUrl . '"' : 'null' !!},
validatorUrl: {!! isset($validatorUrl) ? '"' . $validatorUrl . '"' : 'null' !!},
oauth2RedirectUrl: "{{ route('l5-swagger.'.$documentation.'.oauth2_callback') }}",
requestInterceptor: function(request) {
request.headers['X-CSRF-TOKEN'] = '{{ csrf_token() }}';
return request;
},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
persistAuthorization: true,
})
您可以找到其他需要的参数。找到了解决方案。只要把“persistAuthorization:true”放在招摇过市上,我的问题就解决了 供应商\l5 swagger\index.blade.php
const ui = SwaggerUIBundle({
dom_id: '#swagger-ui',
url: "{!! $urlToDocs !!}",
operationsSorter: {!! isset($operationsSorter) ? '"' . $operationsSorter . '"' : 'null' !!},
configUrl: {!! isset($configUrl) ? '"' . $configUrl . '"' : 'null' !!},
validatorUrl: {!! isset($validatorUrl) ? '"' . $validatorUrl . '"' : 'null' !!},
oauth2RedirectUrl: "{{ route('l5-swagger.'.$documentation.'.oauth2_callback') }}",
requestInterceptor: function(request) {
request.headers['X-CSRF-TOKEN'] = '{{ csrf_token() }}';
return request;
},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
persistAuthorization: true,
})
您可以找到其他需要的参数