Safe browser Auth Response catch..

safe-browser
#1

I am sending Auth data from Client to safe network and safe Authenticator send me back response.
How do I catch The response??
I am using Electron-react boilerplate in front end.
I am using this code from sending Auth request to safe network

Blockquote
console.log(‘Authorising SAFE application…’);
const appInfo = {
// User-facing name of our app. It will be shown
// in the Authenticator user’s interface.
name: ‘Hello SAFE Network’,
// This is a unique ID of our app
id: ‘net.maidsafe.tutorials.desktop-app’,
version: ‘0.1.0’,
vendor: ‘MaidSafe.net Ltd.’,
bundle: ‘com.github.electron’,
customExecPath
};
const opts = {
forceUseMock: true
};
safeApp = await safeNodeApp.initialiseApp(appInfo, null, opts);
const authUri = await safeApp.auth.genAuthUri({});
await safeApp.auth.openUri(authUri);

1 Like
Catching Auth response from Safe authenticatior.
#2

Have you initialized the customExecPath variable?
From the Node JS tutorial the variable should be intialized as follows before creating the appInfo variable.

const app = require('electron').remote.app;
const customExecPath = [process.execPath, app.getAppPath()];

Once appInfo is initialized correctly with the customExePath set, when we call the initializeApp API, a custom URI for your application is registered. Once the authenticator authorizes your application it opens the uri which has the authorization string response.

Further down in the tutorial you will see how the uponAuthResponse function receives this auth response and calls the loginFromUri API to establish a connection to the network.

2 Likes
#3

Yes I have initialized the customExecPath variable.
uponAuthResponse function get a parameter called restAuthUri.
From where I’ll get that?

#4

If you look at main.js#76 an event is triggered when the electron application is opened from a URI - in this case resAuthUri.

Then, in controller.js#5 the event calls the uponAuthResponse function passing the URI it recieved.

The auth response is sent along with the URI. The URI would be something like this:
safe-<base64_encoded_appId>://<auth response string>

1 Like
#5

It is not working…
In React-Elctron boiler plate

#6

You can give it a try using the boilerplate available here:

It would also be helpful if you share your code in a repository, so we can try out the boilerplate that you are using and give you a solution :slight_smile:

1 Like
#7

The open-url event is only available on Mac. Other platforms will need to use the command line args as per here: https://github.com/maidsafe/safe_examples/blob/17628fdab3e734bcaa36819a1ab5648b91b4c33c/safe_app_electron_quick_start/main.js#L39

(@Avirup note that the shouldQuit function is something in electron 2, but was deprecated in newer versions).

From there, you should be able to see passed args and utilise them on linux.

#8

How to catch command line arg in Electron

#9

In the code I linked, it’s passed as a param to code executed as part of the shouldQuit function:

In newer electron versions, it’s here: https://electronjs.org/docs/all#apprequestsingleinstancelock

Catching Auth response from Safe authenticatior.
#10

Thanks…Trying this process.

#11

I have proceeded according to that tutorial.But

app.on('second-instance',

is not triggering…

#12

What version of electron are you using?

You can find previous versions of docs using the electron site, eg: https://electronjs.org/docs/api/app/history

Also: have you registered the app path as @lionel.faber suggested above? Safe browser Auth Response catch..