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

Updated mobile initialize documentation, added new instructions for I… #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pages/fraud-prevention/mobile-app-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ interface AuthApiService {
@Body fingerprint: FingerprintEventRequest,
): Response<FingeprintResult>
}

```
</Tab>
<Tab>
Expand Down Expand Up @@ -251,7 +252,6 @@ function registerUser(username: string) {
// Account already registered, suggest to the user to log in with that existing account
// Keyri.login(username)
});

}

function sendFingerprintToBackend(body: string): Promise<Response> {
Expand Down Expand Up @@ -295,6 +295,7 @@ recommend explicitly setting the attribute in your manifest as shown below:
...
</application>
</manifest>

```

[](https://github.com/Keyri-Co/keyri-android-whitelabel-sdk/blob/master/keyrisdk/src/main/java/com/keyrico/keyrisdk/backup/BACKUP.md#control-backup-on-android-11-and-lower)**Control
Expand All @@ -311,6 +312,7 @@ on devices running Android 11 (API level 30) or lower.
<application android:fullBackupContent="@xml/backup_rules">
...
</application>

```

2. Create an XML file called `@xml/backup_rules` in the `res/xml/` directory.
Expand All @@ -323,6 +325,7 @@ on devices running Android 11 (API level 30) or lower.
<include domain="sharedpref" path="." />
<exclude domain="sharedpref" path="device.xml" />
</full-backup-content>

```

If you have more granular control over sharedPref backups, make sure you have
Expand All @@ -344,6 +347,7 @@ running Android 12 or higher.
<application android:dataExtractionRules="backup_rules.xml">
...
</application>

```

2. Create an XML file called `backup_rules.xml` in the `res/xml/` directory.
Expand All @@ -358,6 +362,7 @@ running Android 12 or higher.
<exclude domain="sharedpref" path="device.xml" />
</cloud-backup>
</data-extraction-rules>

```

If you have more granular control over sharedPref backups, make sure you have
Expand Down Expand Up @@ -453,6 +458,7 @@ After it just add your `MyBackupAgent` to `AndroidManifest.xml`:
</activity>
</application>
</manifest>

```

Or you can just use
Expand All @@ -468,6 +474,7 @@ implements the necessary logic under the hood as shown below:&#x20;
</activity>
</application>
</manifest>

```

### Testing backup
Expand All @@ -487,4 +494,3 @@ sure to disclose the following data collection practice:

An analogous disclosure is not required for iOS apps, since the device data is
not used by Keyri for cross-app tracking.

2 changes: 2 additions & 0 deletions pages/mobile-app-security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Please be sure to install Keyri mobile SDKs as outlined in our documentation:

### Enabling Emulator Detection

// TODO: Change impl

The SDK constructor has `blockEmulatorDetection` set to `true` by default. This
is to allow for local development of your application on an emulator without the
SDK terminating the application. If you would like to deny the running of your
Expand Down
2 changes: 2 additions & 0 deletions pages/mobile-app-security/tamper-detection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ performed by the SDK at initialization automatically.

## Checksum Registration

// TODO: Add impl

<Tabs items={['iOS', 'Android']}>
<Tab>// iOS instructions</Tab>
<Tab>// Android instructions</Tab>
Expand Down
24 changes: 12 additions & 12 deletions pages/mobile-sdks/api-reference/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ override fun onCreate(savedInstanceState: Bundle?) {
appKey,
publicApiKey,
serviceEncryptionKey,
true, // blockEmulatorDetection
payload,
publicUserId
publicUserId,
)

// Or with on activityResult:
Expand All @@ -262,9 +261,8 @@ override fun onCreate(savedInstanceState: Bundle?) {
appKey,
publicApiKey,
serviceEncryptionKey,
true, // blockEmulatorDetection
payload,
publicUserId
publicUserId,
)
}
}
Expand Down Expand Up @@ -319,9 +317,8 @@ private void processLink(Uri intentData) {
appKey,
publicApiKey,
serviceEncryptionKey,
true, // blockEmulatorDetection
payload,
publicUserId
publicUserId,
);

// Or with on activityResult:
Expand All @@ -334,9 +331,8 @@ private void processLink(Uri intentData) {
appKey,
publicApiKey,
serviceEncryptionKey,
true, // blockEmulatorDetection
payload,
publicUserId
publicUserId,
);
});
}
Expand Down Expand Up @@ -420,6 +416,8 @@ The following methods are available to interact with the Keyri SDK API, which ca

- `suspend fun Keyri.register(publicUserId: String?): Result<RegisterObject>` - call this method to generate object for register which includes publicKey and userId

- `suspend fun Keyri.getCorrectedTimestampSeconds(): Long` - call this method to get timestamp (in seconds) synchronized with NTP

- `suspend fun Session.confirm(payload: String, context: Context, trustNewBrowser: Boolean = false): Result<Unit>` - call this function if user confirmed the dialog. Returns authentication result or Throwable error

- `suspend fun Session.deny(payload: String, context: Context): Result<Unit>` - call if the user denied the dialog. Returns denial result or Throwable error
Expand All @@ -442,9 +440,9 @@ The following methods are available to interact with the Keyri SDK API, which ca

- `suspend fun Keyri.removeAssociationKey(publicUserId: String): Result<Unit>` - removes association public key for the specified publicUserId

- `fun easyKeyriAuth(content: Context, easyKeyriAuthLauncher: ActivityResultLauncher<Intent>, appKey: String, publicApiKey: String?, serviceEncryptionKey: String?, blockEmulatorDetection: Boolean = true, payload: String, publicUserId: String?)` - launches scanner activity with default confirmation screen for ActivityResultLauncher
- `fun easyKeyriAuth(content: Context, easyKeyriAuthLauncher: ActivityResultLauncher<Intent>, appKey: String, publicApiKey: String?, serviceEncryptionKey: String?, payload: String, publicUserId: String?, detectionsConfig: KeyriDetectionsConfig = KeyriDetectionsConfig())` - launches scanner activity with default confirmation screen for ActivityResultLauncher

- `fun easyKeyriAuth(activity: Activity, requestCode: Int, appKey: String, publicApiKey: String?, serviceEncryptionKey: String?, blockEmulatorDetection: Boolean = true, payload: String, publicUserId: String?)` - launches scanner activity for result with default confirmation screen for onActivityResult
- `fun easyKeyriAuth(activity: Activity, requestCode: Int, appKey: String, publicApiKey: String?, serviceEncryptionKey: String?, payload: String, publicUserId: String?, detectionsConfig: KeyriDetectionsConfig = KeyriDetectionsConfig())` - launches scanner activity for result with default confirmation screen for onActivityResult

- `@Composable fun EasyKeyriAuth(sheetState: ModalBottomSheetState, coroutineScope: CoroutineScope, keyri: Keyri, sessionId: String, payload: String, publicUserId: String?, result: (Result<Unit>) -> Unit)` - handle process flow with passed scanned url and showing default confirmation screen. Easiest way to process session from deeplink

Expand All @@ -465,6 +463,8 @@ Payload can be anything (session token or a stringified JSON containing multiple

- `void KeyriSdk.register(@Nullable String publicUserId, KeyriCallback<RegisterObject> callback)` - call this method to generate object for register which includes publicKey and userId

- `void KeyriSdk.getCorrectedTimestampSeconds(KeyriCallback<Long> callback)` - call this method to get timestamp (in seconds) synchronized with NTP

- `void KeyriSession.confirm(String payload, Context context, boolean trustNewBrowser, KeyriCallback<Unit> callback)` - call this function if user confirmed the dialog. Returns authentication result or Throwable error

- `void KeyriSession.deny(String payload, Context context, KeyriCallback<Unit> callback)` - call if the user denied the dialog. Returns denial result or Throwable error
Expand All @@ -487,9 +487,9 @@ Payload can be anything (session token or a stringified JSON containing multiple

- `void KeyriSdk.removeAssociationKey(String publicUserId, KeyriCallback<Unit> callback)` - removes association public key for the specified publicUserId

- `void EasyKeyriAuth.easyKeyriAuth(Context content, ActivityResultLauncher<Intent> easyKeyriAuthLauncher, String appKey, @Nullable String publicApiKey, @Nullable String serviceEncryptionKey, String payload, boolean blockEmulatorDetection, String payload, @Nullable String publicUserId)` - launches scanner activity with default confirmation screen for ActivityResultLauncher
- `void EasyKeyriAuth.easyKeyriAuth(Context content, ActivityResultLauncher<Intent> easyKeyriAuthLauncher, String appKey, @Nullable String publicApiKey, @Nullable String serviceEncryptionKey, String payload, String payload, @Nullable String publicUserId, KeyriDetectionsConfig detectionsConfig)` - launches scanner activity with default confirmation screen for ActivityResultLauncher

- `void EasyKeyriAuth.easyKeyriAuth(Activity activity, int requestCode, String appKey, @Nullable String publicApiKey, @Nullable String serviceEncryptionKey, String payload, boolean blockEmulatorDetection, String payload, @Nullable String publicUserId)` - launches scanner activity for result with default confirmation screen for onActivityResult
- `void EasyKeyriAuth.easyKeyriAuth(Activity activity, int requestCode, String appKey, @Nullable String publicApiKey, @Nullable String serviceEncryptionKey, String payload, String payload, @Nullable String publicUserId, KeyriDetectionsConfig detectionsConfig)` - launches scanner activity for result with default confirmation screen for onActivityResult

### Session Object

Expand Down
7 changes: 4 additions & 3 deletions pages/mobile-sdks/api-reference/cordova.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ the Keyri dashboard
Keyri.initialize({
appKey: appKey,
publicApiKey: publicApiKey,
serviceEncryptionKey: serviceEncryptionKey,
blockEmulatorDetection: true
serviceEncryptionKey: serviceEncryptionKey
})
.then((isSuccess) => {
console.log('CordovaKeyri.initialize', isSuccess);
Expand Down Expand Up @@ -142,12 +141,14 @@ The following methods are available to interact with the Keyri SDK API, which ca

- `initiateQrSession(sessionId: string, publicUserId?: string): Promise<KeyriSession>` - call it after obtaining the sessionId from QR code or deep link. Returns Session object with Risk attributes (needed to show confirmation screen) or Exception

- `initializeDefaultConfirmationScreen(payload: string): Promise<boolean>` - to show Confirmation with default UI. Returns Boolean result. Also, you can implement your custom Confirmation Screen, just inherit from BaseConfirmationDialog.kt
- `initializeDefaultConfirmationScreen(payload: string): Promise<boolean>` - to show Confirmation with default UI. Returns Boolean result

- `login(publicUserId?: string): Promise<LoginObject>` - call this method to generate object for login which includes timestampNonce, signature, publicKey and userId

- `register(publicUserId?: string): Promise<RegisterObject>` - call this method to generate object for register which includes publicKey and userId

- `getCorrectedTimestampSeconds(): Promise<number>` - call this method to get timestamp (in seconds) synchronized with NTP

- `confirmSession(payload: string, trustNewBrowser?: boolean): Promise<boolean>` - call this function if user confirmed the dialog, trustNewBrowser is false by default. Returns Boolean authentication result

- `denySession(payload: string): Promise<boolean>` - call if the user denied the dialog. Returns Boolean authentication result
Expand Down
19 changes: 13 additions & 6 deletions pages/mobile-sdks/api-reference/flutter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void main() {
const String appKey = "[Your app key here]"; // Change it before launch
const String? publicApiKey = null; // Change it before launch, optional
const String? serviceEncryptionKey = null; // Change it before launch, optional
const bool blockEmulatorDetection = true;
const String? publicUserId = null; // Change it before launch, optional

class MyApp extends StatelessWidget {
Expand All @@ -92,7 +91,7 @@ class KeyriHomePage extends StatefulWidget {
}

class _KeyriHomePageState extends State<KeyriHomePage> {
Keyri keyri = Keyri(appKey, publicApiKey: publicApiKey, serviceEncryptionKey: serviceEncryptionKey, blockEmulatorDetection: true);
Keyri keyri = Keyri.primary(appKey, publicApiKey: publicApiKey, serviceEncryptionKey: serviceEncryptionKey);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -160,7 +159,7 @@ class KeyriScannerAuthPage extends StatefulWidget {
class _KeyriScannerAuthPageState extends State<KeyriScannerAuthPage> {
bool _isLoading = false;

Keyri keyri = Keyri(appKey, publicApiKey: publicApiKey, serviceEncryptionKey: serviceEncryptionKey, blockEmulatorDetection: true);
Keyri keyri = Keyri.primary(appKey, publicApiKey: publicApiKey, serviceEncryptionKey: serviceEncryptionKey);

void onMobileScannerDetect(BarcodeCapture barcodes) {
if (barcodes.barcodes.isNotEmpty && !_isLoading) {
Expand Down Expand Up @@ -244,6 +243,7 @@ class _KeyriScannerAuthPageState extends State<KeyriScannerAuthPage> {
});
}
}

```

## Deep linking
Expand All @@ -263,6 +263,7 @@ To handle Universal Links (e.g., for QR login straight from the user's built-in
</array>
</dict>
</plist>

```

This will handle all links with the following scheme: `https://{yourCompany}.onekey.to?sessionId={sessionId}`
Expand All @@ -278,11 +279,14 @@ func application(_ application: UIApplication, continue userActivity: NSUserActi
else {
return false
}

let keyri = KeyriInterface(appKey: appKey)
keyri.processLink(url: incomingURL, payload: 'Custom', publicUserId: 'username')

keyri.processLink(url: incomingURL, payload: 'Custom', publicUserId: 'example@mail.com')

return true
}

```

**Note:** Keyri will set up the required `/.well-known/apple-app-site-association` JSON at your `https://{yourSubdomain}.onekey.to` page as required by Apple to handle Universal Link handling. Details on this mechanism are described here: https://developer.apple.com/documentation/Xcode/supporting-associated-domains
Expand All @@ -306,6 +310,7 @@ To handle Android App Links \(e.g., for QR login straight from the user's built-
</intent-filter>
</activity>
</application>

```

In the activity where the processing of links is declared, you need to add handlers in the `onNewIntent()` and `onCreate()` methods, and pass \`sessionId\` to \`easyKeyriAuth\` method:
Expand Down Expand Up @@ -337,13 +342,13 @@ private fun processLink(data: Uri?) {
"[Your appKey]", // Get this value from the Keyri dashboard
"[Your publicApiKey]", // Get this value from the Keyri dashboard, optional,
"[Your serviceEncryptionKey]", // Get this value from the Keyri dashboard, optional
true, // blockEmulatorDetection
"Custom payload here",
"public-User-ID", // publicUserId is optional
)
}
} ?: Log.e("Keyri", "Failed to process link")
}

```

## Interacting with the API
Expand All @@ -354,12 +359,14 @@ The following methods are available to interact with the Keyri SDK API, which ca

- `Future<bool> easyKeyriAuth(String payload, {String? publicUserId})` - handle process flow with passed scanned url and showing default confirmation screen. Easiest way to process session from deeplink

- `Future<bool> initializeDefaultConfirmationScreen(String payload)` - to show Confirmation with default UI. Returns Boolean result. Also, you can implement your custom Confirmation Screen, just inherit from BaseConfirmationDialog.kt
- `Future<bool> initializeDefaultConfirmationScreen(String payload)` - to show Confirmation with default UI. Returns Boolean result

- `Future<LoginObject> login({String? publicUserId})` - call this method to generate object for login which includes timestampNonce, signature, publicKey and userId

- `Future<RegisterObject> register({String? publicUserId})` - call this method to generate object for register which includes publicKey and userId

- `Future<int> getCorrectedTimestampSeconds() ` - call this method to get timestamp (in seconds) synchronized with NTP

- `Future<bool> confirmSession(String payload, bool trustNewBrowser)` - call this function if user confirmed the dialog, trustNewBrowser is false by default. Returns Boolean authentication result

- `Future<bool> denySession(String payload)` - call if the user denied the dialog. Returns Boolean authentication result
Expand Down
Loading