Displaying an announcement to the user at login#
You can configure Blitz Identity Provider to show an announcement to the user upon login. This can show the user one or two buttons, and the user’s choice can be analyzed in the login procedure.
Procedure#
The InfoPipe
procedure allows ads to be shown to the user at 30-day intervals when they log in. The following changes must be made to the procedure before it can be used:
in the
requiredNews()
function, adjust the criteria for displaying the ad - for example, in the example it is set to show once every 30 days if the user clicked the refuse button last time the ad was displayed;in the
DOMAIN
constant, specify theURI
at which Blitz Identity Provider is accessible from the user’s browser;настроить notification type in the configuration file;
configure notification text and button names in messages.
public class InfoPipe implements Strategy {
private final Logger logger = LoggerFactory.getLogger("com.identityblitz.idp.flow.dynamic");
private final static String DOMAIN = "example.com";
@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) {
if (ctx.user() == null || ctx.user().requiredFactor() == null ||
ctx.user().requiredFactor().equals(ctx.justCompletedFactor()))
if (requiredNews("user_agreement", ctx)) return showNews("user_agreement", ctx);
else return StrategyState.ENOUGH();
else
return StrategyState.MORE(new String[] {});
}
private boolean requiredNews(final String pipeId, final Context ctx) {
Long readOn = ctx.user().userProps().numProp("pipes.info." + pipeId + ".disagreedOn");
return (readOn == null || Instant.now().getEpochSecond() - readOn > 30*86400);
}
private StrategyState showNews(final String pipeId, final Context ctx) {
String uri = "https://" + DOMAIN + "/blitz/pipes/info/start?&pipeId=" + pipeId + "&appId=_blitz_profile";
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 the blitz.prod.local.idp.built-in-pipes
section, in which assign the id
identifier specified in the procedure and the type
announcement type to the auxiliary application with the info
type. The following announcement configurations are possible:
news
- a single button is displayed,agreement
- two buttons are displayed.
Example configuration of two info
helper applications with identifiers alarm
and user_agreement
:
"built-in-pipes": {
"choice": [],
"info": [
{
"id": "alarm",
"type": "news",
"userReadAttr": "userInformed"
},
{
"id": "user_agreement",
"type": "agreement"
}
]
}