Skip to content

Authorization: Bearer token is not present in header #27

@eriCCsan

Description

@eriCCsan

Hi, I have been using this plugin. I figured it all out myself, but now I am stuck.
I just want to send a bearer token in the header within the api request. but the token is not being sent.
I have successfully logged in my Keycloak tells me that a sessions has been created.

After a little research, I found something that might be missing here. The requestInterceptor.
Maybe I'm doing this completely wrong? I'm using the password flow as it doesn't need to be that secure as it's just for testing.

Any advice would be appreciated.

<script>
    window.onload = function() {
        const ui = SwaggerUIBundle({
            url: "http://localhost:8000/v3/api-docs",
            dom_id: '#swagger-ui',
            deepLinking: true,
            presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIStandalonePreset
            ],
            plugins: [
                SwaggerUIBundle.plugins.DownloadUrl
            ],
            oauth2RedirectUrl: "http://localhost:8000/oauth2-redirect.html",
            requestInterceptor: function(request) {
                if (window.authorizedAccessToken) {
                    request.headers['Authorization'] = "Bearer " + window.authorizedAccessToken;
                }
                return request;
            }
        })
    }
</script>

EDIT:
After a while I found out that Swagger does not save the token in the browser and therefore cannot be used. But how do you save the token in the browser with this plugin?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions