Extension Point: OpenID Connect Claims Extractor
Basics
Parameter | Value |
---|---|
Extension Point Key | OIDC_CLAIMS_EXTRACTOR |
Extension Point Name | OpenID Connect Claims Extractor |
Extension Interface | OpenIdClaimsExtractor |
Supports Multiple Extensions? | Yes |
Selector Type | None |
Available Since | 1.2.0 |
Use Cases
Extensions implementing this Extension Point can optionally return an XPFOrderHold
object indicating the reason why the order relating to the details passed in the context should be held. This will cause the order to go into an ON_HOLD
state until a business user either releases or rejects the order in Commerce Manager.
Methods
getCustomScopes
The getCustomScopes
method is invoked when a client retrieves the OpenID Connect configuration from Cortex. It allows the plugin to append to the list of scopes that the front-end should pass to the Identity Provider when the user is redirected to the authentication endpoint.
extractClaims
The extractClaims
method is invoked during the token exchange process when a client posts to the openidconnectform
in Cortex. It allows the plugin to retrieve claim values from the Identity Provider (in context.getOpenIdClaims().getClaims()
) and return then in the XPFOpenIdClaimsExtractionResult
. Cortex collects the responses from all extensions and combines them so that the customer profile attribute values and customer group collections can be updated.
Extension Sample
import java.util.HashSet;
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.OIDC_CLAIMS_EXTRACTOR, priority = 1000)
public class ElasticPathOpenIdClaimsExtractor extends XPFExtensionPointImpl implements OpenIdClaimsExtractor {
private static final Map<String, String> OIDC_CLAIM_KEYS_TO_CUST_PROFILE_KEYS = ImmutableMap.of(
"email", "CP_EMAIL",
"given_name", "CP_FIRST_NAME",
"family_name", "CP_LAST_NAME",
"phone_number", "CP_PHONE",
"locale", "CP_PREF_LOCALE");
@Override
public Set<String> getCustomScopes() {
// No scopes to add
return Collections.emptySet();
}
@Override
public XPFOpenIdClaimsExtractionResult extractClaims(final XPFOpenIdClaimsExtractionContext context) {
Map<String, String> openIdClaims = context.getOpenIdClaims().getClaims();
Map<String, String> customerProfileAttributes = new HashMap<>(
openIdClaims.entrySet().stream()
.filter(entry -> OIDC_CLAIM_KEYS_TO_CUST_PROFILE_KEYS.containsKey(entry.getKey()))
.collect(Collectors.toMap(entry -> OIDC_CLAIM_KEYS_TO_CUST_PROFILE_KEYS.get(entry.getKey()), Map.Entry::getValue))
);
Set<String> customerSegments = new HashSet<>();
String loyaltyLevel = context.getOpenIdClaims().getClaims().get("loyalty_level");
if (loyaltyLevel != null && loyaltyLevel.equals("GOLD")) {
customerSegments.add("GOLD_MEMBER");
}
XPFOpenIdClaimsExtractionResult result = new XPFOpenIdClaimsExtractionResult();
result.setCustomerProfileAttributes = customerProfileAttributes;
result.setCustomerSegments = customerSegments;
}
}