-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Boot Swagger 2 UI Oauth2 configuration #767
Comments
Have you tried pasting the swagger json into http://editor.swagger.io? It may be a bug with the swagger ui. Also, when you have described the security context, there is no need for the authorization annotation. SecurityContext is a way to describe the security requirements for Apis that match a particular criteria. In your case it's Apis that match the criteria of |
thanks for the fast reply..
But when I look into Fiddler only following single request is submitted
And this OPTIONS request obviously doesn't succeed |
You might want to report this issue to the swagger-ui/swagger-editor projects. Its really not the scope of this library |
thanks for your help.. i finally found out that i had incorrect cors settings |
@haidelber How did you fix this issue. I am facing the same issue. " authentication button appears in Swagger UI but isn't invokable. There isn't even any js attachted to this button.". Please let me know what's was incorrect in your configuration |
You probably need to add a CORS filter |
@dilipkrish. I applied the CORS filter, but it does't fix the issue. |
@vivekpandian as @dilipkrish mentioned try it with the swagger editor if it's working there your overall settings are correct. But to be honest I didn't get it running with springfox-swagger-ui but my next approach is to configure swagger-ui myself from https://github.com/swagger-api/swagger-ui and write the necessary js to get it running. And take care of HTTP OPTIONS calls in the CORS filter. The browsers issues these preflight requests automatically before cross origin request (http://www.html5rocks.com/en/tutorials/cors/) |
I have the very same issue, with springfox-swagger-ui 2.1.2. In order to make the button work, I had to open the swagger-ui.html in browser first, then enter the following snippet from swagger-oauth.js, after loading the swagger-ui.html,
|
Hi guys, I experienced exactly this issue and I was able to fix the bug in my project using Springfox version 2.2.2 (currently the last published). I have only tried it out with the OAuth2 'implicit' flow which is the one I'm using but I guess it will work with the other flows also. I would like to share what I found out with you. The issue shows (and looks like) a JS error not allowing to turn on the OAuth2 switch. However, the problem is not the JS code. I found the bug in the Java classes that allows to write the proper SpringFox-Swagger-OAuth2 setup (you can't pass the 'clientSecret' using SecurityConfiguration class!). The problem that we can see in the JS code is located in the following method (initOAuth) because there is not way no initialize the 'clientSecret' parameter from Java (is always 'null'). However, if the parameter has no value is treated like an error and the function returns straight away without excuting the code that initializes the OAuth swicht icon. Here is the code: function initOAuth(opts) { appName = (o.appName||errors.push('missing appName')); if(errors.length > 0){ $('pre code').each(function(i, e) {hljs.highlightBlock(e)}); As I said, nothing wrong with the JS code (apart from the fact that an addtional condition could be added so that if the grant type is "implicit" then the "clientSecret" parameter is no mandatory - as the OAuth2 spec says that the secret is not mandatory for this flow). springfox.documentation.swagger.web.SecurityConfiguration from springfox-swagger-common library. The problem is that this class that can be used to specify the configuration does not allows to set the 'clientSecret' attribute (at least in version 2.2.2). /*
*/ import com.fasterxml.jackson.annotation.JsonInclude; @JsonInclude(value = JsonInclude.Include.NON_NULL) private String clientId; private SecurityConfiguration() { public SecurityConfiguration(String clientId, String clientSecret, String realm, String appName, String apiKey, @JsonProperty("clientId") @JsonProperty("realm") @JsonProperty("appName") @JsonProperty("apiKey") @JsonProperty("clientSecret") @JsonProperty("apiKey") Now that is possible to specify a "clientSecret" in the Java setup you can pass the client secret required according to your OAuth2 flow or you can pass an empty String for instance if your flow is 'implicit'. From your Java setup using Spring Boot you could create the SecurityConfig bean like this:
Where the last parameter "" would be the secret. In this case implicit flow so I just pass "". With this changes it works with version 2.2.2 and implicit grant type. Please let me know If I could help more with this. Regards |
Hi, I just pull the last changes because I wanted to pull-request the change suggested in my previous comment and I see exactly this change was done after version 2.2.2 was released. |
Hi guys, Just to point out something I have seen in last version of class SecurityConfiguration.java in sprinfox-swagger-common project (in 'master' branch). I guess the following code: Should be (just the @JsonProperty annotation value was wrong): @JsonProperty("scopeSeparator") Regards! |
Fix issue #767, duplicate @JsonProperty
@miguelfgar could you please describe what should I pass as realm, apiKey, appName? |
I have faced the same case, but i have no idea what should be pass as realm ,apiKey and appName |
i am getting same issue in 2.4.0. Authentication button not opening any popup. Please help |
What issue are you getting @vijaychd ☝️ there are a variety of issues. Have you tried any of the suggestions above? |
Oauth button doesn't work. i applied CORS filter and used latest release. Is there anything i should try? |
My Oauth button doesn't work either. No known solution as of now. |
facing same issue , did you get any solution yet |
@trvajjala This issue has been fixed in 2.5.0, Please create a new issue if it is still a problem |
I have some troubles getting Swagger UI running for my OAuth2 secured API with the current 2.0.0 release.
I guess I'm missing something..
I used following Configuration
My API methods are annotated like that
The Result
The problem now is that the authentication button appears in Swagger UI but isn't invokable. There isn't even any js attachted to this button.
The text was updated successfully, but these errors were encountered: