Display a list of value selections to the user at login#

You can configure after login Blitz Identity Provider to show the user a selection box from a list of values and store the result of the selection in an attribute in the user’s account.

Procedure#

The ChoicePipe procedure allows the user to show the value list selection pages on login. The following changes must be made to the procedure before it can be used:

  • in the DOMAIN constant instead of <BLITZ-HOST> specify the URI where Blitz Identity Provider is accessible from the user’s browser, and in the CLIENT_ID constant instead of <CLIENT_ID> specify the application identifier (with permissions to scope openid) on behalf of which the helper application will be executed;

  • set the notification type in the configuration file;

  • set notification text and button names in messages.

public class ChoicePipe implements Strategy {

    private final Logger logger = LoggerFactory.getLogger("com.identityblitz.idp.flow.dynamic");

    private final static String DOMAIN = "<BLITZ-HOST>";
    private final static String CLIENT_ID = "<CLIENT_ID>";

    @Override public StrategyBeginState begin(final Context ctx) {
        if ("login".equals(ctx.prompt())){
            List<String> methods = new ArrayList<String>(Arrays.asList(ctx.availableMethods()));
            methods.remove("cls");
            return StrategyState.MORE(methods.toArray(new String[0]), true);
        } else {
            if(ctx.claims("subjectId") != null)
                return StrategyState.ENOUGH();
            else
                return StrategyState.MORE(new String[]{});
        }
    }

    @Override
    public StrategyState next(Context ctx) {
        List<List<String>> choice = new ArrayList<List<String>>(){};
        choice.add(Arrays.asList("Value 1"));
        choice.add(Arrays.asList("Value 2"));
        try {
            if (ctx.user() == null || ctx.user().requiredFactor() == null
                    || ctx.user().requiredFactor().equals(ctx.justCompletedFactor())) {
                String res = new ObjectMapper().writeValueAsString(choice);
                String choiceJson = Base64.getUrlEncoder().encodeToString(res.getBytes("UTF-8"));
                return choice(ctx, choiceJson);
            }
            else
                return StrategyState.MORE(new String[] {});
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private StrategyState choice(final Context ctx, final String choiceJson) {
        String uri = "https://" + DOMAIN + "/blitz/pipes/choice/start?appId=" + CLIENT_ID + "&pipeId=select_value&choices=" + choiceJson;
        Set<String> claims = new HashSet<String>(){{
            add("instanceId");
        }};
        Set<String> scopes = new HashSet<String>(){{
            add("openid");
        }};
       return StrategyState.ENOUGH_BUILDER()
         .withPipe(uri, CLIENT_ID, scopes, claims)
         .build();
    }
}

Adding a procedure to blitz.conf#

in the blitz.conf configuration file add a section blitz.prod.local.idp.built-in-pipes in which assign to the auxiliary application with choice` type the identifier ``id specified in the procedure and the name of the attribute claim in which save the selection result.

Configuration example of the choice helper application:

"built-in-pipes": {
    "choice": [
        {
            "id": "select_value",
            "claim": "role"
        }
    ]
}