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

Basic auth shouldn't require a password change reverted? #5410

Closed
RedwoodForest opened this issue Jun 18, 2019 · 6 comments · Fixed by #5812
Closed

Basic auth shouldn't require a password change reverted? #5410

RedwoodForest opened this issue Jun 18, 2019 · 6 comments · Fixed by #5812

Comments

@RedwoodForest
Copy link

I am using swagger-ui version 3.19.5 (via Swashbuckle.AspNetCore.SwaggerUI v4.0.1) with an API that uses basic auth with a username but no password.

(One example of a high traffic and well-designed API that uses this approach for authentication is the Stripe API.)

It looks like in #2114 swagger-ui was changed to not require a password, but in the authorize dialog the password seems to always be required.

Was reverting this change intentional? Is there a workaround I can use to make it optional?

@RedwoodForest RedwoodForest changed the title Basic auth shouldn't a password change reverted? Basic auth shouldn't require a password change reverted? Jun 19, 2019
@heldersepu
Copy link
Contributor

I think all that needs to be done is to remove the required flag here:

: <Col><Input required="required"

@RedwoodForest
Copy link
Author

@heldersepu

I agree.

We found that removing this attribute manually via the browser inspector fixes the issue so we wrote a Swagger plugin as a temporary workaround until this is fixed. (There is almost certainly a more idiomatic way to do this in React, but it's not a framework I'm familiar with.)

// Workaround for https://github.com/swagger-api/swagger-ui/issues/5410
// Based on https://stackoverflow.com/questions/52775462/how-to-insert-minor-customization-into-swagger-inside-its-markup
const BasicAuthPasswordOptionalPlugin = function () {
    return {
        wrapComponents: {
            // We're wrapping the Auths component used to display the authentication prompt:
            // https://github.com/swagger-api/swagger-ui/blob/v3.19.5/src/core/components/auth/auths.jsx
            auths: (Original, system) => (props) => {
                var wrapperClass = system.React.createClass({
                    componentDidMount: function () {
                        var passwordElement = document.querySelector(".auth-container input[type='password']");
                        // The password input field is only present if credentials have not already been entered yet
                        if (passwordElement !== null) {
                            passwordElement.removeAttribute("required");
                        }
                    },
                    render: function () {
                        return system.React.createElement(Original, props);
                    }
                });
                return system.React.createElement(wrapperClass, null);
            }
        }
    }
}

configObject.plugins = [BasicAuthPasswordOptionalPlugin];

@heldersepu
Copy link
Contributor

@bodnia, @webron, @fehguy You guys worked on #2114 should we just remove the required="required" on:

: <Col><Input required="required"

@leseb83
Copy link

leseb83 commented Aug 26, 2019

Hi,
I also need this issue to be solved.
Thanks!

@shockey
Copy link
Contributor

shockey commented Aug 26, 2019

PR is welcome to remove the required attribute 😄

@Simran-B
Copy link
Contributor

Just ran into this issue and since a solution was proposed but no PR yet, here is one: #5812

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

Successfully merging a pull request may close this issue.

5 participants