如何在Angular App中实现Hyperledger Composer Rest服务器的本地Passport策略

ste*_*ess 8 passport-local hyperledger-composer angular

我试图在使用本地护照的hyperledger-composer中验证身份.

我正在网上搜索在角度应用程序中使用的API(即角度应用程序和其他服务器之间的接口).

我什么都找不到.

所以我创建了一个认证服务,假装我使用的是Angular Firebase(即除了composer-rest-server之外的一个单独的服务器,仅用于身份验证),并标记了我需要等效护照本地的代码行(见下文):

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;
    }

}
Run Code Online (Sandbox Code Playgroud)

为了完整性,这里是AuthService使用的AuthData接口:

export interface AuthData {
    email: string;
    password: string;
}
Run Code Online (Sandbox Code Playgroud)

所以我要搜索的是以下三段代码的护照本地等价物:

1.)

this.angularFireAuth.auth.createUserWithEmailAndPassword(
            authData.email, 
            authData.password
);
Run Code Online (Sandbox Code Playgroud)

2.)

this.angularFireAuth.auth.signInWithEmailAndPassword(
            authData.email, 
            authData.password
);
Run Code Online (Sandbox Code Playgroud)

3.)

this.angularFireAuth.auth.signOut();
Run Code Online (Sandbox Code Playgroud)

使用Angular Firebase命令,身份验证工作正常,所以如果我有这三个部分,基于本地护照的身份验证也可以正常工作.

我会非常感谢任何帮助!