Azure AD B2C extra parameters with dynamic values to authorization requests #197
-
I have successfully incorporated the servlet-client project into our application and can dynamically switch between two oauth2 oidc providers Salesforce & Keycloak. I now need to add a third; Azure AD B2C, however it doesn't seem to align with the others. Comparing for example the authorize requests below for Salesforce and Azure, how can I customize the ClientRegistration to cater for the extra runtime parameters / tenant information that Azure needs? Salesforce: response_type: code
client_id: {clientId}
scope: openid
state: JEGBCuU-QONVNAlfZ2Wi9GpJ3Erewf9iWFsQ6X5csJo=
redirect_uri: https://localhost:8444/login/oauth2/code/sf
code_challenge_method: S256
nonce: CqS7Z7dMMH3hms6H4S6MAcw9-aUHkybCJZSTbSrrzfM
code_challenge: OSeYXPb6Bq8x79AEsJlJGm3X6j5V0u802IbTAwrNato Azure AD B2C: response_type: code
client_id: {clientId}
scope: {clientId} openid
state: xL-KgZffYma3tDZA72ogiLEi-zmLaCQLReRCmSYSPQQ=
redirect_uri: https://localhost:8444/openId
code_challenge_method: S256
nonce: yfIRs5jFFRf7OGyQltiWNh4VdR-YgygLuAD1hP8KC80
code_challenge: cMehFikOVs_Lbu--DdHlK_MbCV5e_Apwm7HxYWpcVTw
p: B2C_1A_RPRetrieveQuoteQA3
x-client-SKU: spring-boot-starter
product: car
style: new
ujt: retrievequote
response_mode: form_post |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
If you're using Provided that the cardinality of possible parameters is reasonable: # Double-check this values against what you actually get from .well-known/openid-configuration
azure-authorization-endpoint: https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize
azure-token-endpoint: https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token
azure-jwks-endpoint: https://login.microsoftonline.com/${tenant}/discovery/v2.0/keys
azure-client-id: change-me
azure-client-secret: change-me
scheme: http
server:
port: 8080
spring:
security:
oauth2:
client:
provider:
azure-ad-b2c:
jwk-set-uri: ${azure-jwks-endpoint}
authorization-uri: ${azure-authorization-endpoint}
token-uri: ${azure-token-endpoint}
registration:
azure-retrieve-quote:
authorization-grant-type: authorization_code
client-id: ${azure-client-id}
client-secret: ${azure-client-secret}
provider: azure-ad-b2c
scope: ${azure-client-id},openid
redirect-uri: ${scheme}://localhost:${server.port}/login/oauth2/code/azure-retrieve-quote
azure-save:
authorization-grant-type: authorization_code
client-id: ${azure-client-id}
client-secret: ${azure-client-secret}
provider: azure-ad-b2c
scope: ${azure-client-id},openid
redirect-uri: ${scheme}://localhost:${server.port}/login/oauth2/code/azure-save
com:
c4-soft:
springaddons:
oidc:
client:
authorization-params:
azure-retrieve-quote:
p: B2C_1A_RPRetrieveQuoteQA3
x-client-SKU: spring-boot-starter
product: car
style: new
ujt: retrievequote
response_mode: form_post
azure-save:
p: B2C_1A_RPSaveQA3
x-client-SKU: spring-boot-starter
product: car
style: new
ujt: save
response_mode: form_post Note that:
If you don't use If you use
This would look something like that: @Component
public class MyOAuth2AuthorizationRequestResolver extends SpringAddonsOAuth2AuthorizationRequestResolver {
public MyOAuth2AuthorizationRequestResolver(
OAuth2ClientProperties bootClientProperties,
ClientRegistrationRepository clientRegistrationRepository,
SpringAddonsOidcClientProperties addonsClientProperties) {
super(bootClientProperties, clientRegistrationRepository, addonsClientProperties);
}
@Override
protected Consumer<Builder> getOAuth2AuthorizationRequestCustomizer(HttpServletRequest request, String clientRegistrationId) {
return new CompositeOAuth2AuthorizationRequestCustomizer(
getCompositeOAuth2AuthorizationRequestCustomizer(clientRegistrationId),
new MyDynamicCustomizer(request));
}
static class MyDynamicCustomizer implements Consumer<OAuth2AuthorizationRequest.Builder> {
private final HttpServletRequest request;
public MyDynamicCustomizer(HttpServletRequest request) {
this.request = request;
}
@Override
public void accept(OAuth2AuthorizationRequest.Builder authorizationRequest) {
authorizationRequest.additionalParameters(params -> {
// TODO: add the parameters which depend on the request
});
}
}
} |
Beta Was this translation helpful? Give feedback.
If you're using
spring-addons-starter-oidc
and if the values for Azure authorization endpoint proprietary parameters are static, you should be able to do this with just properties.Provided that the cardinality of possible parameters is reasonable: