Skip to content

Instantly share code, notes, and snippets.

@skiph
skiph / rndemo-Bridging-Header.h
Created May 9, 2018
rndemo ios-swift bridging header
View rndemo-Bridging-Header.h
// rndemo rndemo-Bridging-Header.h
#import <React/RCTBridgeModule.h>
@skiph
skiph / ApproovBridge.m
Created May 9, 2018
rndemo - native bridge implementation
View ApproovBridge.m
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(Approov, NSObject)
RCT_EXTERN_METHOD(fetchApproovToken:(NSString *)url
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
)
@end
@skiph
skiph / Approov.swift
Created May 9, 2018
rndemo: swift bridging class
View Approov.swift
import Foundation
import Approov
@objc(Approov)
class Approov: NSObject {
@objc func fetchApproovToken(_ url: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
let attestee = ApproovAttestee.shared()
@skiph
skiph / native-module-call.js
Last active May 2, 2018
RNDemo - native module call
View native-module-call.js
import {NativeModules} from 'react-native';
NativeModules.Approov.fetchApproovToken(input)
.then(token => {
// do something useful...
})
.catch((error) => {
throw error;
});
@skiph
skiph / AppFragment.js
Last active May 2, 2018
RNDemo - App getShape fragment
View AppFragment.js
import Approov from './Approov';
class App extends React.Component {
// unchanged code ommitted for brevity...
// get shape
getShape = () => {
Approov.fetch('https://demo-server.approovr.io/shapes', {
@skiph
skiph / Approov.js
Last active May 2, 2018
RNDemo - Approov module wrapper
View Approov.js
import {NativeModules} from 'react-native';
const fetchWithToken = (input, options) => {
return NativeModules.Approov.fetchApproovToken(input)
.then(token => {
let optionsA = (options? {...options, headers:{ ...options.headers}}:{headers: {}});
optionsA.headers['Approov-Token'] = token;
return fetch(input, optionsA)
.then((response) => {
@skiph
skiph / MainApplication.java
Last active Apr 27, 2018
RNDemo - Main Application.java
View MainApplication.java
package com.rndemo;
import ...
import com.criticalblue.approov.ApproovPackage;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
@skiph
skiph / ApproovPackage.java
Last active May 2, 2018
RNDemo - Approov Package
View ApproovPackage.java
package com.criticalblue.approov;
import ...
public class ApproovPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@skiph
skiph / ApproovModule.java
Last active Apr 27, 2018
RNDemo - Approov native module
View ApproovModule.java
package com.criticalblue.approov;
import ...
import com.criticalblue.attestationlibrary.ApproovAttestation;
import com.criticalblue.attestationlibrary.ApproovConfig;
import com.criticalblue.attestationlibrary.TokenInterface;
class ApproovModule extends ReactContextBaseJavaModule {
@skiph
skiph / ShapeView.js
Created Apr 27, 2018
RNDemo - shapes component
View ShapeView.js
import React from "react";
import { View, Image, Text, StyleSheet } from "react-native";
const shapeView = (props) => {
const imgSrc = {
'logo': require('./assets/approov_largelogo.png'),
'hello': require('./assets/hello.png'),
'confused': require('./assets/confused.png'),
'Rectangle': require('./assets/rectangle.png'),
'Square': require('./assets/square.png'),