Catching Auth response from Safe authenticatior.

One option is to use Safenetworkjs which is independent of the framework, and can be used for desktop (eg electron) or Web. But whether you want to build on the Safenetworkjs API or not is something you’d need to think about.

Or you could also extract the relevant code from Safenetworkjs (see src/bootstrap.js) as auth is fairly well isolated. It might even be a good idea to produce a very cut down library ‘Safeauthjs’ to do just that, but I’m too busy to do that myself.

I’m not sure what you’re asking here, can you clarify a bit please.

With auth_cli you were referring to the command line authenticator and not the one in the browser - weren’t you…?

Because I do understand that the whole authenticator concept is needed for mobile but I don’t understand why we wouldn’t expose a simple launcher scheme with local server interface with the browser for desktop applications …?

Well… Sure - all within limits… If everything is possible but you need to invest weeks to get started the bird will look ugly and never fly… If you make it easy for people to fall in love with the project but some pieces are missing they might want to help to add those pieces …

Indeed. The CLI authenticator project.

This is what I’m suggesting exists at the moment: GitHub - maidsafe-archive/safe-authenticator-cli: This crate implements a CLI for the safe_authenticator crate.

Only different being it’s not tied to the browser.

1 Like

Agreed, and that’s why I try to fill in where Maidsafe don’t have time, by offering help on here, building stuff to learn and show, and creating projects that help people use and develop.

We can’t have everything at once so each of us must prioritise. We can debate priorities of course - that’s what we’re doing no!? :slight_smile:

I know what you’ve had to go through is hard and a big barrier for everyone who wants to build because I had to do it too. Not just the SAFE API, but the whole JavaScript ecosystem was new to me. I was lucky I had the time… and that the project has taken so long :rofl:

All along the way I’ve looked at where I was and tried to figure out the most productive thing I could be doing to help the project. To start it was mostly learning, and discussing, then researching what to build and how, followed by porting simple Web apps created by others, then starting on a library, then more learning and trying to integrate with Solid, and eventually creating my first thing from scratch (SAFE Drive).

All of this is hard. But I like that because I get bored doing stuff I know too much about, so again I’m lucky that I have the time and enjoy the learning.

Most people have much less time and so I do get it, that more people could do more stuff if it was easier and quicker. So I hear you and am always trying to help people with that, at the same time as trying to encourage and share.

The hard work you’ve done is incredibly valuable - not wasted - and can help others. I think you can see this already, I certainly can.

So I hope you and others are not discouraged by things being hard, but realise there’s extra value created by those like you who can do some of the hard stuff, and make it easier for, and give help to those who follow. :+1:

1 Like

I cannot get any response uri from safe browser after authentication…

My problem is still there…

1 Like

In the docs it is stated there…

const asyncFn = async () => {
  try {
    const app = await safe.initialiseApp(appInfo);
    const authReqUri = await app.auth.genAuthUri(containerPermissions);
    await app.auth.openUri(authReqUri);
    // After URI is opened by SAFE Authenticator and authorised,
    // this snippet assumes that your application has an
    // IPC strategy to receive returned authorisation uri.
    await app.auth.loginFromUri(authUri);

Can anyone tell me how to create ipc strategy??

Sorry @Avirup for highjacking your topic

I guess the best way for you would be

Since you are using JS aren’t you?

If you want to do your own implementation I would advise you to research system uris and have a look at GitHub - maidsafe-archive/system_uri: Desktop System App URI registration handler

You need to open the link safe-authenticator://encodedAuthenticationRequest or so to initiate the authentication process and the authenticator then opens a link for your app where it puts the answer as argument

How to implement this in Electron ipc??

Hi @Avirup, have you taken a look at what @ravinderjangra suggested?

If you look at that tutorial and look at the boilerplate code we use there you will see how an auth reponse is received from an electron app:

If you are creating an electron aplication you’ll need to do the same as we do in that boilerplate.

EDIT: I see there is also another thread where you’ve been helped out, so we can continue on that one.

Hi,
We tried few other methods we could find. Now we are using Peruse browser to authenticate our app. Our authorization request as follows…

async requestAuth() {
    try {
      const safeApp = await initialiseApp(this.appInfo, null, this.opts);
      const authUri = await safeApp.auth.genAuthUri(
        this.containerPermissions,
        this.authorisationOptions
      );
      console.log('Auth URI generated: ', authUri);
      await safeApp.auth.openUri(authUri);
      return;
    } catch (err) {
      throw err;
    }
  }

This is called from our actions

And we try to get IPC message on our index.js

We have been trying to pass this initial authorization step for past few weeks and failing. Kindly have a look into our source code. Any help is appreciated.

@joshuef @happybeing @bochaco

Peruse browser has been deprecated and won’t work with the current SAFE API. Make sure you use the latest SAFE Browser from:

3 Likes

Wow things getting deprecated so fast. Ok so just tried with latest SAFE browser. But still we are unable to retrieve any response from network. :thinking:

@0mkara , I just ran your app and I can see at least four issues (apart from what @happybeing already pointed out, you need to use latest version of the browser since you are using safe-node-app package v0.11.x):

1- the browser is not telling you why the authorisation request you are sending is incorrect or malformed (issue #454). This is fixed already and will be part of the very next release of the browser to be available in the next few days, so stay tuned to downlod the new version when ready.

2- I assume you are trying with alpha2 network, since your package.json script start ("start": "cross-env NODE_ENV=production electron ./app/main.prod.js") is always starting it for alpha/real network and not for mock. Therefore if you are running a browser for mock, it won’t accept the authorisation request you are generating as it’s not for mock (here it’s where you should be receiving an error in the browser as I mentioned above for issue 454). If you want to generate auth request for mock you need to set NODE_ENV=test

3- your authorisation request is malformed since you are trying to request permissions for an invalid container, i.e. you are requesting permissions for public container instead of _public. If you change this the browser v0.12.x will show you the authorisation popup correctly. However, in this case the browser should handle the error too and it’s not, so I just raised issue #697 for the browser since the error should be sent back to the app as a response so it can hadle it properly.

4- you are not registering the app’s URI scheme for receiving the authorisation response, this is because you are setting registerScheme: false in here which should be set to true

6 Likes

Thank you very much for pointing out my mistakes. I will fix those and come back to the thread. :+1:

2 Likes

@0mkara also, just to be thorough, you need to ensure your electron app can do something with the passed URI once it is registered, please see @bochaco’s other post above.

The ipc message you were trying to use isn’t provided by default.

2 Likes

Are there any video tutorials for safe authentication process using electron-react ??

Hunter uses the cli authenticator in the Electron overview video here:

Thanks…