It sounds like you're trying to implement an OAuth 2.0 or OpenID Connect server. The implementation of such is outside of the scope of Swagger tooling.
If you have such a server in place (or even better if you use a battle testing identity provider), then you can leverage it to protect your APIs using OpenAPI spec. See the OAuth 2.0 docs for information on how to configure the security schemes.
Once an API description (i.e. an OpenAPI definition) has been setup correctly with the relevant security schemes and the path items require security, then the `Authorize` button in SwaggerUI will render the appropriate form for you to enter the appropriate data and communicate with the configured OAuth provider.
You can also set the OAuth configuration before user interaction, you can also refer to here