Swagger/Swashbuckle Authorize. Scopes checked by default
Asked Answered
F

2

13

Is it possible to set an auth scope checkbox checked by default on Swashbuckle UI on a asp.net Core 2.0 Web API??

I use the "openid" scope and I'd like to have it checked every time.

Thank you.

enter image description here

Fermin answered 20/2, 2018 at 17:18 Comment(5)
Swashbuckle UI ?!? _ Maybe you mean Swagger UI? Can you include some screenshots?Adscription
Yes, I mean Swagger UI. I have edit the question to add the screen shoot where there is authorize model with the checkbox that I want to have it always checked.Fermin
@Fermin just came across your question, did you ever find a solution to this? I was trying to do the same.Seritaserjeant
Any solution to this now?Inopportune
Related thread on GitHub - github.com/swagger-api/swagger-ui/issues/5895Sink
D
6

This is now possible. In the options for SwaggerUI use

options.OAuthScopes("<myapi>");
Delorsedelos answered 10/6, 2022 at 11:52 Comment(0)
S
3

Here is hacktastic workaround for modern browsers which can be injected into index.html.

function checkScopes(container) {
  const inputNodes = container.querySelectorAll(".scopes input");
  for (const checkbox of inputNodes) {
    checkbox.click();
    console.log('Scope checkbox modified: ' + checkbox.id);
  }
}

function watchDOM() {
  // target element that we will observe
  const target = document.body;

  // subscriber function
  function subscriber(mutations) {
    mutations.forEach((mutation) => {
      if (mutation.target.className == 'auth-wrapper') {
        checkScopes(mutation.target);
      }
    });
  }

  // instantiating observer
  const observer = new MutationObserver(subscriber);

  // observing target
  observer.observe(target, { childList: true, subtree: true });
};

document.addEventListener('DOMContentLoaded', watchDOM);
Sporocyst answered 31/3, 2020 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.