Last active
April 27, 2018 01:11
-
-
Save skiph/6c26465f9d2db9ec785e8c3484d8142f to your computer and use it in GitHub Desktop.
RNDemo - Approov native module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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