Skip to content

Instantly share code, notes, and snippets.

@skiph

skiph/ApproovModule.java

Last active Apr 27, 2018
Embed
What would you like to do?
RNDemo - Approov native module
package com.criticalblue.approov;
import ...
import com.criticalblue.attestationlibrary.ApproovAttestation;
import com.criticalblue.attestationlibrary.ApproovConfig;
import com.criticalblue.attestationlibrary.TokenInterface;
class ApproovModule extends ReactContextBaseJavaModule {
private static final String E_APPROOV_ERROR = "E_APPROOV_ERROR";
private Context context;
public ApproovModule(ReactApplicationContext reactContext) {
super(reactContext);
this.context = reactContext;
try {
ApproovConfig config = ApproovConfig.getDefaultConfig(reactContext);
ApproovAttestation.initialize(config);
} catch (IllegalArgumentException ex) {
} catch (MalformedURLException ex) {
}
}
@Override
public String getName() {
return "Approov";
}
@ReactMethod
public void fetchApproovToken(final String url, final Promise promise) {
ApproovAttestation.shared().fetchApproovToken(new TokenInterface() {
@Override
public void approovTokenFetchResult(ApproovResults results) {
if (results.getResult() == ApproovAttestation.AttestationResult.SUCCESS)
promise.resolve(results.getToken());
else
promise.reject(E_APPROOV_ERROR, "Failed to fetch Approov Token");
}
}, url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment