'Spring doc oauth2RedirectUrl with wrong server
I'm writing my first question, please be patient if anything is missing. Any Feedback is welcome.
We have an issue with the generated oauth2RedirectUrl after migrating from a Windows 2012 R2 to a Windows 2016. The server is no longer containing the alias name but the technical server name.
We are using Spring Boot 2.6.0 including spring-boot-starter-oauth2-resource-server and springdoc-openapi-ui 1.5.12. Spring Boot is set up as a resource server with JWT authorization with Azure OAuth2.
We deploy a FAT Jar on windows machines and recently changed to a new server. Each machine is has a DNS entry with a technical name and a human readable alias. Lets say
- human-readable-name1 for the old machine
- human-readable-name2 for the new machine
We deployed the exact same software on both machines. We access the sawagger ui with
https://human-readable-name1.domain:port/swagger-ui.html
and
https://human-readable-name2.domain:port/swagger-ui.html
The response from both machines include the generated api-docs which are looking fine. Containing on both machines like
"servers": [
{
"url": "https://human-readable-name.domain:port",
"description": "Generated server url"
}
]
But the swagger-config change
OLD
{
"configUrl": "/v3/api-docs/swagger-config",
"oauth2RedirectUrl": "https://human-readable-name1:port/swagger-ui/oauth2-redirect.html",
"url": "/v3/api-docs",
"validatorUrl": ""
}
NEW
{
"configUrl": "/v3/api-docs/swagger-config",
"oauth2RedirectUrl": "https://technicalname:port/swagger-ui/oauth2-redirect.html",
"url": "/v3/api-docs",
"validatorUrl": ""
}
This breaks the log in as the token is no longer reaching the swagger ui client.
Any suggestions where I even can start looking for the reason?
Swagger config:
@Configuration
class OpenApiConfig {
@Value("${springdoc.oAuthFlow.authorizationUrl}")
private String authorizationUrl;
@Value("${springdoc.oAuthFlow.tokenUrl}")
private String tokenUrl;
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("security_auth",
new SecurityScheme()
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.authorizationCode(new OAuthFlow()
.authorizationUrl(authorizationUrl)
.tokenUrl(tokenUrl)
.scopes(new Scopes()
.addString("xxx", "xxx")
)
)
)
)
)
.addSecurityItem(new SecurityRequirement().addList("security_auth"))
;
}
}
Spring Boot yaml
spring.security.oauth2.resourceserver.jwt:
jwk-set-uri: https://login.microsoftonline.com/common/discovery/v2.0/keys
issuer-uri: https://login.microsoftonline.com/xxx/v2.0
springdoc:
swagger-ui:
oauth:
clientId: 'xxx'
use-pkce-with-authorization-code-grant: true
oAuthFlow:
authorizationUrl: https://login.microsoftonline.com/xxx/oauth2/v2.0/authorize
tokenUrl: https://login.microsoftonline.com/xxx/oauth2/v2.0/token
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
