Skip to content

Commit

Permalink
Update readme files, simply the app link workflow which can be used b…
Browse files Browse the repository at this point in the history
…y iOS integration in the future.
  • Loading branch information
vincent-dfinity committed Sep 8, 2023
1 parent 6b828bc commit bf23f9f
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 251 deletions.
16 changes: 8 additions & 8 deletions native-apps/unity_ii_applink/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Internet Identity Integration
This sample shows one way to integrate Internet Identity with Android apps. It contains two parts: a dapp with II integrated, and an Unity Project which interacts with this dapp.

## ii_integration_page
## ii_integration_dapp
It's an example that integrates with Internet Identity, with the backend and frontend. It derives from the [Internet Identity integration sample](https://github.com/dfinity/examples/tree/master/motoko/internet_identity_integration) demo with some modifications.
Please refer to [README](./ii_integration_page/README.md) for details.
Please refer to [README](./ii_integration_dapp/README.md) for details.

## android_integration
This is a Unity project with [ICP.NET](https://github.com/BoomDAO/ICP.NET) embedded, which is a C# agent that is able to communicate with the IC from C#. Please refer to [README](./android_integration/README.md) for details.
## unity_project
This is a Unity project with [ICP.NET](https://github.com/BoomDAO/ICP.NET) embedded, which is a C# agent that is able to communicate with the IC from C#. Please refer to [README](./unity_project/README.md) for details.

## Workflow
Before continuing, please read through the [Android App Links](https://developer.android.com/studio/write/app-link-indexing) to understand how Android App Links works.
Expand All @@ -15,10 +15,10 @@ Here is the basic workflow that how to integrate with Internet Identity from a U

The steps in detail are described below:

1. Set up an [Internet Identity integration dapp](#ii_integration_page) which supports logging in with II, with an `assetlinks.json` file associated.
Please refer to [ii_integration_page](./ii_integration_page/README.md) to set up the dapp.
2. Run a Unity game on Android, which is built from [android_integration sample](#android_integration).
Please refer to [android_integration](./android_integration/README.md) to build the Unity Android game.
1. Set up an [Internet Identity integration dapp](#ii_integration_dapp) which supports logging in with II, with an `assetlinks.json` file associated.
Please refer to [ii_integration_dapp](./ii_integration_dapp/README.md) to set up the dapp.
2. Run a Unity game on Android, which is built from [android_integration sample](#unity_project).
Please refer to [unity_project](./unity_project/README.md) to build the Unity Android game.
3. Launch the Web Browser from the game to open the dapp frontend deployed in #1, with the public key of `Ed25519Identity` as a parameter.
4. Login with your Internet Identity in the Web Browser.
5. Launch the application via App Links, and pass the `DelegationIdentity` back to the game as the URL parameter.
Expand Down
2 changes: 1 addition & 1 deletion native-apps/unity_ii_applink/ii_integration_dapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Here is an example of [.ic-assets.json](./src/greet_frontend/assets/.ic-assets.j

Once you set up the IC development environment locally and update the example as you want, you can follow the below steps to deploy to the IC mainnet.

1. Enter the `ii_integration_page` directory from the command line
1. Enter the `ii_integration_dapp` directory from the command line
2. Run `npm install` to install the npm packages
3. Run `dfx start --background`
4. Run `dfx deploy --network=ic --with-cycles=1000000000000`
Expand Down
1 change: 0 additions & 1 deletion native-apps/unity_ii_applink/unity_project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

# Gradle cache directory
.gradle/
gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using UnityEngine;
using EdjCase.ICP.Candid.Utilities;
using Newtonsoft.Json;
using System.Web;

namespace IC.GameKit
{
public class DeepLinkPlugin : MonoBehaviour
{
TestICPAgent mTestICPAgent = null;

private void Awake()
{
// Register action for deep link activated.
Application.deepLinkActivated += OnDeepLinkActivated;
}

public void Start()
{
mTestICPAgent = gameObject.GetComponent<TestICPAgent>();
}

public void OpenBrowser()
{
var target = mTestICPAgent.greetFrontend + "?sessionkey=" + ByteUtil.ToHexString(mTestICPAgent.TestIdentity.PublicKey.Value);
Application.OpenURL(target);
}

public void OnDeepLinkActivated(string url)
{
if (string.IsNullOrEmpty(url))
return;

const string kDelegationParam = "delegation=";
var indexOfDelegation = url.IndexOf(kDelegationParam);
if (indexOfDelegation == -1)
{
Debug.LogError("Cannot find delegation");
return;
}

var delegationString = HttpUtility.UrlDecode(url.Substring(indexOfDelegation + kDelegationParam.Length));
var delegation = JsonConvert.DeserializeObject<DelegationChainModel>(delegationString);
mTestICPAgent.Delegation = delegation;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
using System.Collections.Generic;
using EdjCase.ICP.Agent.Models;
using System;
using System.IO;
using Newtonsoft.Json;
using System.Web;

namespace IC.GameKit
{
public class TestICPAgent : MonoBehaviour
{
public string greetFrontend = "https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io/";
public string greetBackendCanister = "72rj2-biaaa-aaaan-qdatq-cai";

Text mMyPrincipalText = null;
Button mGreetButton = null;
Ed25519Identity mEd25519Identity = null;
DelegationChainModel mDelegation = null;

public Ed25519Identity TestIdentity { get { return mEd25519Identity; } }

internal DelegationChainModel Delegation {
get { return mDelegation; }
set
{
mDelegation = value;

if (mDelegation != null && mGreetButton != null)
{
mGreetButton.interactable = true;
}
}
}

// Start is called before the first frame update
void Start()
{
Expand All @@ -41,33 +53,6 @@ void Update()
{
}

public void OnMessageSent(string delegationPath)
{
if (string.IsNullOrEmpty(delegationPath) || !File.Exists(delegationPath))
return;

//Debug.Log("Identity path '" + identityPath + "' exists.");

var parameters = File.ReadAllText(delegationPath);
//Debug.Log("Params length is: " + parameters.Length);

const string kDelegationParam = "delegation=";
var indexOfDelegation = parameters.IndexOf(kDelegationParam);
if (indexOfDelegation == -1)
{
Debug.LogError("Cannot find delegation");
return;
}

var delegationString = HttpUtility.UrlDecode(parameters.Substring(indexOfDelegation + kDelegationParam.Length));
mDelegation = JsonConvert.DeserializeObject<DelegationChainModel>(delegationString);

if (mDelegation != null && mGreetButton != null)
{
mGreetButton.interactable = true;
}
}

public void Greet()
{
if (mDelegation == null)
Expand Down Expand Up @@ -99,9 +84,9 @@ private async void CallCanister(DelegationChainModel delegationChainModel)
// Initialize HttpAgent.
var agent = new HttpAgent(delegationIdentity);

Principal canisterId = Principal.FromText(greetBackendCanister);
var canisterId = Principal.FromText(greetBackendCanister);

// Intialize Client and make the call.
// Intialize the client and make the call.
var client = new GreetingClient.GreetingClient(agent, canisterId);
var content = await client.Greet();

Expand Down
Loading

0 comments on commit bf23f9f

Please sign in to comment.