Search in sources :

Example 1 with FirebaseCloudMessagingClient

use of org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingClient in project oxAuth by GluuFederation.

the class CIBAEndUserNotificationService method notifyEndUserUsingFCM.

/**
 * Method responsible to send notifications to the end user using Firebase Cloud Messaging.
 * @param deviceRegistrationToken Device already registered.
 * @param scope Scope of the authorization request
 * @param acrValues Acr values used to the authorzation request
 * @param authReqId Authentication request id.
 */
private void notifyEndUserUsingFCM(String scope, String acrValues, String authReqId, String deviceRegistrationToken) {
    String clientId = appConfiguration.getBackchannelClientId();
    String redirectUri = appConfiguration.getBackchannelRedirectUri();
    String url = appConfiguration.getCibaEndUserNotificationConfig().getNotificationUrl();
    String key = cibaEncryptionService.decrypt(appConfiguration.getCibaEndUserNotificationConfig().getNotificationKey(), true);
    String to = deviceRegistrationToken;
    String title = "oxAuth Authentication Request";
    String body = "Client Initiated Backchannel Authentication (CIBA)";
    RedirectUri authorizationRequestUri = new RedirectUri(appConfiguration.getAuthorizationEndpoint());
    authorizationRequestUri.addResponseParameter(CLIENT_ID, clientId);
    authorizationRequestUri.addResponseParameter(RESPONSE_TYPE, "id_token");
    authorizationRequestUri.addResponseParameter(SCOPE, scope);
    authorizationRequestUri.addResponseParameter(ACR_VALUES, acrValues);
    authorizationRequestUri.addResponseParameter(REDIRECT_URI, redirectUri);
    authorizationRequestUri.addResponseParameter(STATE, UUID.randomUUID().toString());
    authorizationRequestUri.addResponseParameter(NONCE, UUID.randomUUID().toString());
    authorizationRequestUri.addResponseParameter(PROMPT, "consent");
    authorizationRequestUri.addResponseParameter(AUTH_REQ_ID, authReqId);
    String clickAction = authorizationRequestUri.toString();
    FirebaseCloudMessagingRequest firebaseCloudMessagingRequest = new FirebaseCloudMessagingRequest(key, to, title, body, clickAction);
    FirebaseCloudMessagingClient firebaseCloudMessagingClient = new FirebaseCloudMessagingClient(url);
    firebaseCloudMessagingClient.setRequest(firebaseCloudMessagingRequest);
    FirebaseCloudMessagingResponse firebaseCloudMessagingResponse = firebaseCloudMessagingClient.exec();
    log.debug("CIBA: firebase cloud messaging result status " + firebaseCloudMessagingResponse.getStatus());
}
Also used : FirebaseCloudMessagingClient(org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingClient) FirebaseCloudMessagingRequest(org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingRequest) RedirectUri(org.gluu.oxauth.util.RedirectUri) FirebaseCloudMessagingResponse(org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingResponse)

Aggregations

FirebaseCloudMessagingClient (org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingClient)1 FirebaseCloudMessagingRequest (org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingRequest)1 FirebaseCloudMessagingResponse (org.gluu.oxauth.client.ciba.fcm.FirebaseCloudMessagingResponse)1 RedirectUri (org.gluu.oxauth.util.RedirectUri)1