Open ahmedAbouismail opened 2 years ago
Same problem.
Hello and thanks for reporting this problem!
It seems like the upgrade to springdoc-openapi v1.5.9 (due to upgrading Spring Boot from 2.4.4 to 2.5.2) broke this functionality.
I will look into how to reestablish the functionality, but meanwhile you can downgrade the Product Composite service to springdoc-openapi v1.5.2 to make it work again.
Replace the following in $BOOK_HOME/Chapter11/microservices/product-composite-service/build.gradle
:
Replace:
id 'org.springframework.boot' version '2.5.2'
With:
id 'org.springframework.boot' version '2.4.4'
Replace:
springCloudVersion = "2020.0.3"
With:
springCloudVersion = "2020.0.2"
Replace:
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.5.9'
With:
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.5.2'
implementation 'org.springdoc:springdoc-openapi-common:1.5.2'
Also in $BOOK_HOME/Chapter11/test-em-all.bash
, replace:
assertCurl 302 "curl -ks https://$HOST:$PORT/openapi/swagger-ui.html"
With:
assertCurl 307 "curl -ks https://$HOST:$PORT/openapi/swagger-ui.html"
Sorry for the inconvenience, Magnus.
@magnus-larsson Thank you for your reply. It solved the problem. :)
I think I found the underlying problem: https://github.com/spring-projects/spring-authorization-server/issues/680
I'm not sure when this change has been introduced but I started my project with the Authorization Server in version 0.2.1
and now use 0.2.3
and using https://127.0.0.1:8443/webjars/swagger-ui/oauth2-redirect.html
as redirect URI did the trick. It now works!
Edit: No, it does not. The OAuth-Dance works and I get redirected to https://127.0.0.1:8443/webjars/swagger-ui/oauth2-redirect.html?code=_qfCbxYGmOCr3...
and even get a 200
response code but nothing is displayed. In the my browser's console, I see the following error:
Uncaught DOMException: Blocked a frame with origin "https://127.0.0.1:8443" from accessing a cross-origin frame.
at run (https://127.0.0.1:8443/webjars/swagger-ui/oauth2-redirect.html?code=pNWgJpEVMFqf3PWtbxhlA3ltZ4Qtl3xmpabR_cg_eWmrRc1qc1LbSrHzKCoftQe6knpILA51xk2IBfLJutkL12LThPAdwizbWWkh8-S7Zk8ULjut-iT0z3Ld32MUkXEv&state=VGh1IEp1biAxNiAyMDIyIDE2OjQzOjMzIEdNVCswMjAwIChDZW50cmFsIEV1cm9wZWFuIFN1bW1lciBUaW1lKQ%3D%3D:10:36)
at HTMLDocument.<anonymous> (https://127.0.0.1:8443/webjars/swagger-ui/oauth2-redirect.html?code=pNWgJpEVMFqf3PWtbxhlA3ltZ4Qtl3xmpabR_cg_eWmrRc1qc1LbSrHzKCoftQe6knpILA51xk2IBfLJutkL12LThPAdwizbWWkh8-S7Zk8ULjut-iT0z3Ld32MUkXEv&state=VGh1IEp1biAxNiAyMDIyIDE2OjQzOjMzIEdNVCswMjAwIChDZW50cmFsIEV1cm9wZWFuIFN1bW1lciBUaW1lKQ%3D%3D:74:13)
So, still not working but at least one tiny step closer to the problem. 😉
@Partyschaum I applied Magnus recommendations and it started to work
Fixed without any version changes:
after this you will be rewarded with:
security_auth (OAuth2, authorizationCode) Authorized Authorization URL: https://localhost:8443/oauth2/authorize
Token URL: https://localhost:8443/oauth2/token
Flow: authorizationCode
client_id: ** client_secret: **
It also works with Auth0 - just make sure you use (replace {TENANT} with yours): tokenUrl: https://{TENANT}/oauth/token
You could gather all urls used ny Auth0 with this command from the book: curl https://${TENANT}/.well-known/openid-configuration -s | jq
And now, swagger is working with Auth0
In kubernetes the swagger needs adjustment when moving to ingress service to point to the host minikube.me in auth service code for writer and reader redirect url and product-composite config for swagger. Unfortunately, it would not be able to authorize swagger due to https://minikube.me/login" returning 404. The url should be: https://minikube.me:8443/login. The redirect url is also missing port. So it looks like ingress does not forward port (X-Forwarded-Port) to the services in the cluster. I think it is Windows specific as ingress is using 8443 and 8080, on Mac it is using default http(80) and https(443) ports, so this issue is not apparent and swagger is working fine as it does not need port overrides.
As I expected the swagger is working fine in Chapter16 after reconfiguration for port 30443 for fixes to urls above. In Chapter 18 the minikube ingress will be replaced with istio ingress gateway and hopefully this one works correctly with port forwarding. Not so fast, it got even worse as you can not access minikube tunnel from host OS (Windows) - it only available in ubuntu guest OS, but it has no GUI. Time to migrate to Mac OS to continue.
Hello and thanks for reporting this problem!
It seems like the upgrade to springdoc-openapi v1.5.9 (due to upgrading Spring Boot from 2.4.4 to 2.5.2) broke this functionality.
I will look into how to reestablish the functionality, but meanwhile you can downgrade the Product Composite service to springdoc-openapi v1.5.2 to make it work again.
Replace the following in
$BOOK_HOME/Chapter11/microservices/product-composite-service/build.gradle
:
Replace:
id 'org.springframework.boot' version '2.5.2'
With:
id 'org.springframework.boot' version '2.4.4'
Replace:
springCloudVersion = "2020.0.3"
With:
springCloudVersion = "2020.0.2"
Replace:
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.5.9'
With:
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.5.2' implementation 'org.springdoc:springdoc-openapi-common:1.5.2'
Also in
$BOOK_HOME/Chapter11/test-em-all.bash
, replace:assertCurl 302 "curl -ks https://$HOST:$PORT/openapi/swagger-ui.html"
With:
assertCurl 307 "curl -ks https://$HOST:$PORT/openapi/swagger-ui.html"
Sorry for the inconvenience, Magnus.
Thanks Magnus for the efforts to make it works.
After I click on the "Authorize" button, I end up on the login page. But after I enter the credentials, I get redirected to this error page https://localhost:8443/oauth2/authorize?response_type=code&client_id=writer&redirect_uri=https%3A%2F%2Flocalhost%3A8443%2Fopenapi%2Fwebjarshttps%3A%2Flocalhost%3A8443%2Fwebjars%2Fswagger-ui%2Foauth2-redirect.html&scope=chat%3Aread%20chat%3Awrite&state=U2F0IE1heSAyMSAyMDIyIDEyOjI4OjI2IEdNVCswMjAwIChDZW50cmFsIEV1cm9wZWFuIFN1bW1lciBUaW1lKQ%3D%3D
could you help me please?