Forum Discussion

BriaLubiens's avatar
Occasional Visitor
3 years ago

Optional Authentication or "Demo User"

Hello,   I had an idea for an API we are developing and I was wondering if anyone has done this before or would know whether it is possible.   Essentially, we have a generic user set up which has...
  • mhiggins's avatar
    3 years ago

    This is a very common use case for SwaggerHub customers that I work with. 


    However, there is no way in OAS to pre-populate the Authorization pop-up fields in swagger-ui for SwaggerHub.


    Both the swagger-ui panel for Try-It and the swagger-docs page will display and open the Authorization pop-up, but i cannot find any mechanism to pre-populate the fields within.


    One (not very sustainable) solution comes to mind. Have 2 copies (or versions) of the Spec in SwaggerHub:

    • Copy 1 for serious Consumers where they enter their credentials as normal.
    • Copy 2 for the "casual browsers" where you have added a hard-coded Basic Auth or JWT Authorization HEADER to the path methods and no Security tag. You cannot easily do this for the OAuth security schemas. 

    Most customers simply provide the "demo" credentials in the $.info.description section of the Spec (usually bold and large font) with the caveat that users with their own credentials should use those in the Authorization pop-up.