An authorized counter example
- We have a
incrementmethod in backend motoko code, which requires an non-anonymous identity to call. - We try to connect with
internet identityto fetch user's identity. - If the identity is anonymous, the smart contract will return with error
- If the identity is not anoymous, the smart contract will execute the actual
increment.
- agent_dart
- agent_dart_auth
- internet identity(local or mainnet)
- middle page project(auth_client_demo)
agent_dartdoes not provide any UI related feature or components to keep itselfcleanas dart code.agent_dart_authuses an third-party plugin calledflutter_web_authto open up a WebView window to display the middle page.middle pageis used to redirect current authenticating request tointernet identity, the reasons to do so are as folowing:internet identityONLY accept browser request, it useswindowandpostMessageto complete the authentication flow. Thus third party apps like flutter or mobile apps can not pass parameters to it directly.- Why don't we call its contract/canister directly? Because user keeps their II anchor number in their browsers, there's no way to extract those identities out of the browsers.
- The MOST IMPORTANT reason is that, when user authorize DApps on Mainnet, the II will calculate the delegation identity using DApps' url. If the url changes or use localhost, the delegation result will change. Thus we have to use a middle page to trick II we had our requests are from our DApps' webpage, which means you have to deploy at least one webpage to mainnet and to the same and stable auth url to II.
- The
middle pageis a very simple example that how do we complete the flow. There are still limitations:- the project is coded by
lit-html, if you are using React or Vue, you have to transpile yourself. - THere are difference between
androidandiosin auto-redirecting. User have to click whenweb-to-flutterflow on Android, butflutter-to-webflow on iOS.
- the project is coded by
- If you are tyring to use II, currently, no. Limitation is too much there.
- AstroX is implementing our own identity service, which will link II as one of the identity providers. After we finish that part, we will make a flutter plugin to call smart-contract method directly, maybe without Webview popup.
Nikola from Distrikt.io, helped us to come up with the solution.
sidc0des and RMCS from Canistore, helped us to debug latest agent-js dependencies and they complete the service worker for web. Solution and code will come after.