如何在Angular App中为Hyperledger Composer Rest Server实施本地护照策略

时间:2018-08-03 12:42:30

标签: angular hyperledger-composer passport-local

我正在尝试使用本地护照在hyperledger-composer中进行身份验证。

我正在在线搜索要在angular应用程序(即angular应用程序与其余服务器之间的接口)中使用的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;
    }

}

为完整起见,这是AuthService使用的AuthData接口:

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

所以我要搜索的是以下三段代码的本地护照等效内容:

1。)

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

2。)

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

3。)

this.angularFireAuth.auth.signOut();

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

非常感谢您的帮助!

0 个答案:

没有答案