2017-11-20 22 views
0

私はログインフォームを持つ典型的なWebアプリケーションを持っていますが、残りのユーザーを認証するためにバックエンドにfeathersjsを使用しようとしています。フロントエンドには角度4を使用しています。角度4fetahersjs/angularでの認証4

フロントエンド認証サービス:

import { Injectable } from '@angular/core'; 
import { HttpHeaders, HttpClient } from '@angular/common/http'; 
import 'rxjs/add/operator/toPromise'; 

@Injectable() 
export class AuthService { 
    private BASE_URL: string = 'http://localhost:3030'; 
    private headers: HttpHeaders = new HttpHeaders({'Content-Type': 'application/json'}); 
    constructor(private http: HttpClient) {} 

    login(user): Promise<any> { 
    let url: string = `${this.BASE_URL}/authentication`; 
    return this.http.post(url, user, {headers: this.headers}).toPromise(); 
    } 
} 

設定/バックエンドでdefault.json:バックエンドで

"authentication": { 
    "secret": "my-secret", 
    "strategies": [ 
     "jwt", 
     "local" 
    ], 
    "path": "/authentication", 
    "service": "users", 
    "jwt": { 
     "header": { 
     "typ": "access" 
     }, 
     "audience": "https://yourdomain.com", 
     "subject": "anonymous", 
     "issuer": "feathers", 
     "algorithm": "HS256", 
     "expiresIn": "1d" 
    }, 
    "local": { 
     "entity": "teams", 
     "usernameField": "email", 
     "passwordField": "password" 
    } 
    } 

authentication.js

const authentication = require('feathers-authentication'); 
const jwt = require('feathers-authentication-jwt'); 
const local = require('feathers-authentication-local'); 


module.exports = function() { 
    const app = this; 
    const config = app.get('authentication'); 

    // Set up authentication with the secret 
    app.configure(authentication(config)); 
    app.configure(jwt()); 
    app.configure(local()); 

    app.service('authentication').hooks({ 
    before: { 
     create: [ 
     authentication.hooks.authenticate(config.strategies) 
     ], 
     remove: [ 
     authentication.hooks.authenticate('jwt') 
     ] 
    } 
    }); 
}; 

上記で私は/認証エンドポイントのために404を得ています。私は手動で認証エンドポイントを作成する必要がありますか、それとも私のために作成するのですか?あなたは例を挙げることができますか?

+0

なぜ角は全く言及されていますか?問題はバックエンドに固有であり、デバッグしてPostmanなどで複製する可能性があります。はい、 '/ authentication'はこのように動作します。ノードコンソールでauthプラグインからのエラーがないかどうかを再度確認します。 Feathersパッケージのバージョンが関係するため、http://stackoverflow.com/help/mcve(例:repo)の提供を検討してください。 – estus

答えて

1

トリックは、リクエスト本体に「戦略」を含めることです。

{ 
    "email": "[email protected]", 
    "password": "1234", 
    "strategy": "local" 
} 
関連する問題