6

I am trying to wrap my head around authentication in hyperledger-composer using passport-local.

I was searching online for API to use in the angular app (i.e. the interface between the angular app and the rest-server).

I just couldn't find anything.

So I created an authentication service pretending I was using Angular Firebase (i.e. a separate server apart from the composer-rest-server, just for authentication) and marked the lines of code where I need an equivalent for passport-local (see below):

import { AuthData } from './auth-data.model';
import { Subject } from 'rxjs/Subject';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AngularFireAuth } from 'angularfire2/auth';

@Injectable()
export class AuthService {

    private isAuthenticated = false;

    constructor(private router: Router, private angularFireAuth: AngularFireAuth) {}

    registerUser(authData: AuthData): Promise<any> {

        //What is the equivalent to the following line for passport-local ?:
        return this.angularFireAuth.auth.createUserWithEmailAndPassword(
            authData.email, 
            authData.password
        );

    }

    login(authData: AuthData) {
        //What is the equivalent to the following line for passport-local ?:   
       this.angularFireAuth.auth.signInWithEmailAndPassword(
            authData.email, 
            authData.password
        ).then(result => {
            console.log(result);
            this.loggedInSuccessfully();
        })
        .catch(error => {
            console.log(error);
        });

    }

    logout() {
        this.loggedOutSuccessfully();
    }

    isAuth() {
        return this.isAuthenticated;
    }

    private loggedInSuccessfully() {
        this.isAuthenticated = true;
        this.router.navigate(['']);
    }

    private loggedOutSuccessfully() {

       //What is the equivalent to the following line for passport-local ?:          
        this.angularFireAuth.auth.signOut();
        this.router.navigate(['login']);
        this.isAuthenticated = false;
    }

}

For completeness, here is the AuthData Interface used by AuthService:

export interface AuthData {
    email: string;
    password: string;
}

So what I am searching for is the passport-local equivalent for the following three pieces of code:

1.)

this.angularFireAuth.auth.createUserWithEmailAndPassword(
            authData.email, 
            authData.password
);

2.)

this.angularFireAuth.auth.signInWithEmailAndPassword(
            authData.email, 
            authData.password
);

3.)

this.angularFireAuth.auth.signOut();

Using the Angular Firebase commands, authentication works fine, so if I have these three pieces, authentication based on passport-local should work fine too.

I would be very thankful for any help!

steady_progress
  • 3,311
  • 10
  • 31
  • 62

0 Answers0