I've developed a simple DApp that uses uPort and it works fine on Desktop - where I can login through uPort with the QR Code. On a mobile browser (Anrdoid Chrome) I'm auto directed to uPort where it asks me to "continue", then I'm redirected back to my app on mobile where the URL now has a hash of /access_token="{token-here}" But now uport.requestCredentials()
doesn't return the uPort Profile. Am I supposed to manually grab the access token in the url and do something with it?
1 Answer
This problem occurs because mobile browsers often open a new browser tab instead of returning to the original. Until the issue is fixed in uport-connect, here is a workaround.
Install uport-js (normally this is just a server-side library, but we need a function from here):
npm install uport
In the front-end app we create a Credentials object to allow us to handle the access_token on behalf of our uPort app:
import { Credentials } from 'uport';`
const appCredentials = new Credentials({
address: YOUR_APP_UPORT_ADDRESS
});
And then we grab the access token from the URL and convert it to the uPort user credentials object that should have been returned by uport-connect:
var accessToken = window.location.href.split('access_token=')[1];
var uportUserCredentials = await appCredentials.receive(accessToken);
uportCredentials
will now contain your credentials.