私のMEANスタックアプリケーションは、認証にAzure ADを使用しています。私は"passport-azure-ad"モジュールをWeb API認証用に使用しています。ユーザーがすでにクライアント(UI)によって認証された場合post & reply hereに基づいて、私はそのpassport-azure-ad、トークンを解析して検証しますか?
を理解し、その後、すべてのAPI呼び出しのために、 クライアントは、サーバにトークンを送信します。そして、 サーバでは、ベアラ戦略を使用して、ユーザーのAPIへのアクセスを「承認」することができます。
私のシナリオでは、ユーザーが認証されていることを確認して、APIにアクセスできるようにしたかっただけです。
質問
1.サーバーがメソッドを実行「passport.authenticate( 『OAuthのベアラ』)」、パスポート - 紺碧 - 広告が自動的&は、クライアントから受信されたトークンを検証または実行解析します私は追加のステップが必要ですか?
2.トークンを検証できない場合、またはトークンが不正またはスプーフィングされている場合はどうなりますか?ここで
AzureAuthenticationService.js
"use strict";
var passport = require('passport');
var OIDCBearerStrategy = require('passport-azure-ad').BearerStrategy;
var options = {
identityMetadata: 'https://login.microsoftonline.com/tenantid/.well-known/openid-configuration',
validateIssuer: true,
passReqToCallback: false,
loggingLevel: 'error'
};
function configure(app) {
app.use(passport.initialize());
app.use(passport.session());
passport.use(new OIDCBearerStrategy(options,
function(token, done) {
//is there anything else i need to do here?
return done(null, token.unique_name, token);
}));
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (id, done) {
done(null, id);
});
}
function authenticate(req, res, next) {
//is there anything else i need to do here?
passport.authenticate('oauth-bearer')(req, res, next);
}
server.js
'UserServiceの' です私は、データベースからユーザーを取得するために使用され、私はそのAPIを守りたいです私はためのメンテナだ
"use strict";
var authentication = require('./AzureAuthenticationService');
var userService = require('./UserService');
// Initialize server
var express = require('express');
var app = exports.app = express();
authentication.configure(app);
// Set routes
app.get('/api/users',authentication.authenticate,userService.getUsers);