Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass cookies to api #494

Open
max10rogerio opened this issue Sep 22, 2022 · 0 comments
Open

How to pass cookies to api #494

max10rogerio opened this issue Sep 22, 2022 · 0 comments

Comments

@max10rogerio
Copy link

  • L5-Swagger Version: 8.4.1 (composer show | grep l5-swagger)
  • PHP Version (php -v): 8.1.8
  • OS: Ubuntu 20.04

Description:

How to pass cookies to api?

Swagger UI Config

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{config('l5-swagger.documentations.'.$documentation.'.api.title')}}</title>
    <link rel="stylesheet" type="text/css" href="{{ l5_swagger_asset($documentation, 'swagger-ui.css') }}">
    <link rel="icon" type="image/png" href="{{ l5_swagger_asset($documentation, 'favicon-32x32.png') }}" sizes="32x32"/>
    <link rel="icon" type="image/png" href="{{ l5_swagger_asset($documentation, 'favicon-16x16.png') }}" sizes="16x16"/>
    <!-- Load the HierarchicalTags Plugin -->
    <script src="https://unpkg.com/swagger-ui-plugin-hierarchical-tags"></script>
    <style>
    html
    {
        box-sizing: border-box;
        overflow: -moz-scrollbars-vertical;
        overflow-y: scroll;
    }
    *,
    *:before,
    *:after
    {
        box-sizing: inherit;
    }

    body {
      margin:0;
      background: #fafafa;
    }
    </style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="{{ l5_swagger_asset($documentation, 'swagger-ui-bundle.js') }}"></script>
<script src="{{ l5_swagger_asset($documentation, 'swagger-ui-standalone-preset.js') }}"></script>
<script>
    window.onload = function() {
        // Build a system
        const ui = SwaggerUIBundle({
            dom_id: '#swagger-ui',
            url: "{!! $urlToDocs !!}",
            withCredentials: true, // enable cookies here
            operationsSorter: {!! isset($operationsSorter) ? '"' . $operationsSorter . '"' : 'null' !!},
            configUrl: {!! isset($configUrl) ? '"' . $configUrl . '"' : 'null' !!},
            validatorUrl: {!! isset($validatorUrl) ? '"' . $validatorUrl . '"' : 'null' !!},
            oauth2RedirectUrl: "{{ route('l5-swagger.'.$documentation.'.oauth2_callback', [], $useAbsolutePath) }}",

            requestInterceptor: function(request) {
                request.headers['X-CSRF-TOKEN'] = '{{ csrf_token() }}';
                return request;
            },

            presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIStandalonePreset
            ],

            plugins: [
                SwaggerUIBundle.plugins.DownloadUrl,
                HierarchicalTagsPlugin
            ],

            layout: "StandaloneLayout",
            docExpansion : "{!! config('l5-swagger.defaults.ui.display.doc_expansion', 'none') !!}",
            filter: {!! config('l5-swagger.defaults.ui.display.filter') ? 'true' : 'false' !!},
            persistAuthorization: "{!! config('l5-swagger.defaults.ui.authorization.persist_authorization') ? 'true' : 'false' !!}",

        })

        window.ui = ui
    }
</script>
</body>
</html>

Config
image

Curl

curl -X 'GET' \
  'http://localhost:8080/v1/configs/branches?field=name&direction=ASC&page=1&items_per_page=20&type=json' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJraWQiOiJiOThhMDllZTIyYjE0M2I1OGRlMWE3MGFlNjZkMDAwMCIsImFsZyI6IlJTMjU2In0.eyJqdGkiOiJhM2Q0MzZjMS1kMDQ4LTQyYjUtYTUzNy1lYmQzYzkzNzIxZWMiLCJpc3MiOiJuenJ4UzF3Y3IzbGhqa0JKYVliT2Y0RjNCTEd2Y0dFVyIsImlhdCI6MTY2Mzg1MjA3MSwic3ViIjoiNzg3N2U1YjMtYzRlMy00ZDc5LTgzMjAtOTQxN2I0OWJlZTIwIiwiZXhwIjoxNjYzODU1NjcxLCJ0c2kiOiJlNmQyOTdiMS0yOGEyLTQ2YWYtODQwOC1jN2YyNGZkMDFjNzktYWNjZXNzIiwidG9rZW5fdXNlIjoiYWNjZXNzIiwiZW1haWwiOiJtYXguY2FtYXJnb0BnYXppbi5jb20uYnIiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsInJ0ZCI6ImdCYS1hTkpuTFllUy1FUnBkRzliZmZxNHUtT0IyTTJ6OWwzSVdFSzV2ajh6SjBsNm9oMlM0SktyeENCY0ZyUEgiLCJub25jZSI6bnVsbCwic2NvcGVzIjoib3BlbmlkIGVtYWlsIn0.DtNXzl9uQgUObJjV-88I0YR335H_56AnyRKd88ts5pshk_aRKeEh0Cl0zvsqiTkkrwBHiyVLip-NGKuyVcEZb7XIalIn42a8-xVaFJu8YCMil9xY7yS0kreTxh98xelZPlK02Yh_KusVL8Cz47FYJTWIr3zU3KeA3uyaXG1m7OJW4QxfhreHxld96PEUwQn5olMSM-E3iLADyyUdza7YOpj0ACD4VPA4OwQ-YpHqoz0BloaUCzgq1HucTx4lhGK5FbOE_cKBOCISb2ldZI1cZN9xj8nSC-lG8m5MJQLbPZwROk2jUE0-TqgmcoZgG3uevtC1pZdGKaVQMUSLlKU0HA' \
  -H 'Cookie: company_id=5491a88f-ddb2-4948-90b8-b1596b848ad1' \
  -H 'X-CSRF-TOKEN: '

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant