cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Basic Auth to access /rest/v2/swagger-ui.html

04-26-2020 12:45 PM
3045 views 3 comments
0 Likes
SAP Managed Tags
Subscribe

Hello Experts,

Is there a way to add or restrict /rest/v2/swagger-ui.html with HTTP Basic Authentication?

Thanks

Anil

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

gaurav11
Participant
0 Likes

Hi Anilkumar

Please take a look on below link, it would be helpful.

https://swagger.io/docs/specification/authentication/basic-authentication/

Thanks,

Gaurav

Former Member
0 Likes

@areddy34 : yes it is possible to restrict UI with basic authentication. You have to add following configuration in security-v2-spring.xml of commercewebservices extension. After adding following configuration, browser will prompt for username password. The other apis (Cart etc.) exposed would be authorised as usual by Oauth2.

The configurable (username,password) properties you can define in your local.properties.

<!-- Swagger UI security with basic auth -->
<http pattern="/v2/*swagger*/**" xmlns="http://www.springframework.org/schema/security"
      authentication-manager-ref="basicAuthenticationManager">
    <intercept-url pattern="/v2/*swagger*/**" access="isAuthenticated()" />
    <http-basic />
    <csrf />
</http>

<security:authentication-manager id="basicAuthenticationManager">
    <security:authentication-provider>
        <security:user-service>
            <security:user
                    name="#{configurationService.configuration.getProperty('swagger.basicauth.username')}"
                    password="{noop}#{configurationService.configuration.getProperty('swagger.basicauth.password')}"
                    authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>
</security:authentication-manager>


<!-- Commerce Webservices V2-->
<http pattern="/v2/**" entry-point-ref="oauthAuthenticationEntryPointV2"
#######existing configurations##########
srivatsapnb
Newcomer
0 Likes

Hello Experts,

After following the above link , able to get swagger Pop Up. But getting Cookie Expired Error. We are using spartacus .

screenshot-2023-10-10-at-15247-pm.png.

So, wanted to know how we can log into swagger by getting Authorized

Thanks in Advance.

Regards.

P.N.B.Srivatsa