Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rich consents #122

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: provide rich consents client in api client
  • Loading branch information
cgcladeraokta committed Nov 28, 2024
commit a822183589ad8e6a211f24755e4d5271790fd815
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ public DeviceAPIClient device(@NonNull String deviceIdentifier, @NonNull String
return new DeviceAPIClient(requestFactory, baseUrl, deviceIdentifier, token);
}

/**
* Returns an API client to fetch transaction's rich consent record.
*
* @param privateKey the enrollment signing key
* @param publicKey the enrollment public key
* @return an API client for rich consents
*/
public RichConsentsAPIClient richConsents(PrivateKey privateKey, PublicKey publicKey) {
// According to the Guardian SDK guidelines, developers must provide either the Guardian domain
// or the canonical domain including the `/appliance-mfa` path. However, since Rich Consents is
// not an MFA API endpoint, preserving this path will not work.
// As a temporary solution, the `/appliance-mfa` path is stripped from the base URL.
// IMPORTANT: Rich Consents will not function correctly when using the Guardian domain until
// a long term solution is implemented.
String guardianUrl = baseUrl.toString();
if (guardianUrl.contains("/appliance-mfa")) {
guardianUrl = guardianUrl.replace("/appliance-mfa", "");
}
final HttpUrl url = HttpUrl.parse(guardianUrl);
return new RichConsentsAPIClient(requestFactory, url, privateKey, publicKey);
}

private String createBasicJWT(@NonNull PrivateKey privateKey,
@NonNull String audience,
@NonNull String deviceIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.os.Build;
import android.util.Base64;

import com.auth0.android.guardian.sdk.model.RichConsent;
import com.auth0.android.guardian.sdk.networking.Callback;
import com.auth0.android.guardian.sdk.utils.MockCallback;
import com.auth0.android.guardian.sdk.utils.MockWebService;
Expand Down Expand Up @@ -503,6 +504,25 @@ public void shouldCreateValidDeviceAPIWithJWT() throws Exception {
verifyBasicJWT(jwt);
}

@Test
public void shouldCreateValidRichConsentsAPI() throws Exception {
GuardianAPIClient apiClient = new GuardianAPIClient.Builder()
.url(Uri.parse(mockAPI.getDomain() + "appliance-mfa"))
.build();
String consentId = "cns_00000001";

mockAPI.willReturnRichConsent(consentId, "https://api", "openid", "test");

final MockCallback<RichConsent> callback = new MockCallback<>();

apiClient.richConsents(keyPair.getPrivate(), keyPair.getPublic())
.fetch(consentId, "token")
.start(callback);

RecordedRequest request = mockAPI.takeRequest();
assertThat(request.getPath(), is(equalTo(String.format("/rich-consents/%s", consentId))));
}

private Map<String, Object> bodyFromRequest(RecordedRequest request) throws IOException {
Gson gson = new GsonBuilder().create();
Type type = new TypeToken<Map<String, Object>>() {
Expand Down