From eb19b12ee2391b958746774970db70c8ffb12c27 Mon Sep 17 00:00:00 2001 From: Carlos Galan Cladera Date: Mon, 2 Dec 2024 13:01:10 +0100 Subject: [PATCH] feat(app): notificaiton with consent details Implement an example of fetching rich consent record when transaction linking id is present in the notificaiton. --- app/src/main/AndroidManifest.xml | 6 + .../auth0/guardian/sample/MainActivity.java | 5 +- ...otificationWithConsentDetailsActivity.java | 181 ++++++++++++++++++ ...vity_notification_with_consent_details.xml | 121 ++++++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/auth0/guardian/sample/NotificationWithConsentDetailsActivity.java create mode 100644 app/src/main/res/layout/activity_notification_with_consent_details.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index befab07..6855ed5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,6 +36,12 @@ + + + + () { + @Override + public void onSuccess(RichConsent response) { + consentDetails = response; + updateUI(); + } + + @Override + public void onFailure(Throwable exception) { + Log.e(TAG, "Error obtaining consent details", exception); + } + }); + } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { + Log.e(TAG, "Error requesting consent details", e); + } + + } + + private void setupUI() { + bindingMessageText = (TextView) findViewById(R.id.bindingMessage); + scopeText = (TextView) findViewById(R.id.scope); + dateText = (TextView) findViewById(R.id.dateText); + + Button rejectButton = (Button) findViewById(R.id.rejectButton); + assert rejectButton != null; + rejectButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + rejectRequested(); + } + }); + + Button allowButton = (Button) findViewById(R.id.allowButton); + assert allowButton != null; + allowButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + allowRequested(); + } + }); + } + + private void updateUI() { + if (consentDetails != null) { + bindingMessageText.setText(consentDetails.requested_details.binding_message); + scopeText.setText(String.join(", ", consentDetails.requested_details.scope)); + } else { + bindingMessageText.setText("N/A"); + scopeText.setText("N/A"); + } + dateText.setText(notification.getDate().toString()); + } + + private void rejectRequested() { + guardian + .reject(notification, enrollment) + .start(new DialogCallback<>(this, + R.string.progress_title_please_wait, + R.string.progress_message_reject, + new Callback() { + @Override + public void onSuccess(Void response) { + finish(); + } + + @Override + public void onFailure(Throwable exception) { + + } + })); + } + + private void allowRequested() { + guardian + .allow(notification, enrollment) + .start(new DialogCallback<>(this, + R.string.progress_title_please_wait, + R.string.progress_message_allow, + new Callback() { + @Override + public void onSuccess(Void response) { + finish(); + } + + @Override + public void onFailure(Throwable exception) { + + } + })); + } +} diff --git a/app/src/main/res/layout/activity_notification_with_consent_details.xml b/app/src/main/res/layout/activity_notification_with_consent_details.xml new file mode 100644 index 0000000..98602db --- /dev/null +++ b/app/src/main/res/layout/activity_notification_with_consent_details.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +