swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

Fix oauth2-redirect outside of the base swagger path #177

Closed alvarogf97 closed 2 years ago

alvarogf97 commented 2 years ago

Problem

When you use Oaut2 implicit flow, swagger ui sends an url that not includes the path where the swagger ui is located to the authorization page

If you include swaggo in your project like this:

router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

You will get this redirect url in the oauth2 implicit flow:

{protocol}//{host}/oauth2-redirect.html

This url is not found due to his location is {protocol}//{host}/swagger/oauth2-redirect.html actually

Relation issue The issue is #115

Additional context I add the minimun changes to make it work.

PD: sorry for the other changes fmt did his work :D and I think it could be worth

cc: @ubogdan @DeyiXu

The following images belong to my own project that can be a proof of how it works url1 url2

Sorry for my broken english, I'm from Spain :D

codecov[bot] commented 2 years ago

Codecov Report

Merging #177 (c040683) into master (7da8e84) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #177   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           70        81   +11     
=========================================
+ Hits            70        81   +11     
Impacted Files Coverage Δ
swagger.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7da8e84...c040683. Read the comment docs.

ubogdan commented 2 years ago

@alvarogf97 Thanks for your contribution.

alvarogf97 commented 2 years ago

thanks for merging @ubogdan

Could you create a new package release? Thanks!

ubogdan commented 2 years ago

added v1.3.3

DeyiXu commented 2 years ago

Thanks contribution