| @@ -22,6 +22,7 @@ type swaggerConfig struct { · 21 unmodified lines |
| 22 | DefaultModelsExpandDepth int | 22 | DefaultModelsExpandDepth int |
| 23 | DeepLinking bool | 23 | DeepLinking bool |
| 24 | PersistAuthorization bool | 24 | PersistAuthorization bool |
| | 25 | Oauth2DefaultClientID string |
| 25 | } | 26 | } |
| 26 | | 27 | |
| 27 | // Config stores ginSwagger configuration variables. | 28 | // Config stores ginSwagger configuration variables. |
| @@ -34,6 +35,7 @@ type Config struct { · 6 unmodified lines |
| 34 | DefaultModelsExpandDepth int | 35 | DefaultModelsExpandDepth int |
| 35 | DeepLinking bool | 36 | DeepLinking bool |
| 36 | PersistAuthorization bool | 37 | PersistAuthorization bool |
| | 38 | Oauth2DefaultClientID string |
| 37 | } | 39 | } |
| 38 | | 40 | |
| 39 | func (config Config) toSwaggerConfig() swaggerConfig { | 41 | func (config Config) toSwaggerConfig() swaggerConfig { |
| @@ -45,8 +47,9 @@ func (config Config) toSwaggerConfig() swaggerConfig { · 5 unmodified lines |
| 45 | Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" + | 47 | Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" + |
| 46 | "{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" + | 48 | "{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" + |
| 47 | "/oauth2-redirect.html`", | 49 | "/oauth2-redirect.html`", |
| 48 | Title: config.Title, | 50 | Title: config.Title, |
| 49 | PersistAuthorization: config.PersistAuthorization, | 51 | PersistAuthorization: config.PersistAuthorization, |
| | 52 | Oauth2DefaultClientID: config.Oauth2DefaultClientID, |
| 50 | } | 53 | } |
| 51 | } | 54 | } |
| 52 | | 55 | |
| @@ -95,6 +98,13 @@ func PersistAuthorization(persistAuthorization bool) func(*Config) { · 42 unmodified lines |
| 95 | } | 98 | } |
| 96 | } | 99 | } |
| 97 | | 100 | |
| | 101 | // Oauth2DefaultClientID set the default client ID used for OAuth2 |
| | 102 | func Oauth2DefaultClientID(oauth2DefaultClientID string) func(*Config) { |
| | 103 | return func(c *Config) { |
| | 104 | c.Oauth2DefaultClientID = oauth2DefaultClientID |
| | 105 | } |
| | 106 | } |
| | 107 | |
| 98 | // WrapHandler wraps `http.Handler` into `gin.HandlerFunc`. | 108 | // WrapHandler wraps `http.Handler` into `gin.HandlerFunc`. |
| 99 | func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerFunc { | 109 | func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerFunc { |
| 100 | var config = Config{ | 110 | var config = Config{ |
| @@ -105,6 +115,7 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF · 4 unmodified lines |
| 105 | DefaultModelsExpandDepth: 1, | 115 | DefaultModelsExpandDepth: 1, |
| 106 | DeepLinking: true, | 116 | DeepLinking: true, |
| 107 | PersistAuthorization: false, | 117 | PersistAuthorization: false, |
| | 118 | Oauth2DefaultClientID: "", |
| 108 | } | 119 | } |
| 109 | | 120 | |
| 110 | for _, c := range options { | 121 | for _, c := range options { |
| @@ -303,6 +314,13 @@ window.onload = function() { · 192 unmodified lines |
| 303 | defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}} | 314 | defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}} |
| 304 | }) | 315 | }) |
| 305 | | 316 | |
| | 317 | const defaultClientId = "{{.Oauth2DefaultClientID}}"; |
| | 318 | if (defaultClientId) { |
| | 319 | ui.initOAuth({ |
| | 320 | clientId: defaultClientId |
| | 321 | }) |
| | 322 | } |
| | 323 | |
| 306 | window.ui = ui | 324 | window.ui = ui |
| 307 | } | 325 | } |
| 308 | </script> | 326 | </script> |