We have an application written using the MEAN stack. The application currently uses home authentication. We are trying to replace it with Azure AD authentication.
There is a good article here that shows how to configure Angular to authenticate Azure using the ADAL.JS library. This will protect the resources of the client side. In the example, server-side APIs are written using the .Net Web API and OWIN is used to protect the web APIs. Thus, OWIN is responsible for verifying the sending of the token token from the client.
Using the MEAN stack, the server-side API is written to Node.js, so how can we protect the Node.js API if we upgrade to Azure AD? Is there any Node module available from Microsoft? Any example would be greatly appreciated.
Microsoft provides the passport plugin , passport-azure-ad .
passport-azure-ad - , Azure Active Directory. OpenID Connect, WS-Federation SAML-P. Node Microsoft Azure AD, , - (WebSSO), OAuth JWT.
AAD angular, , .
Node.js. Apis angular.
, O365, gitHub, ADAL. https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect/blob/master/authHelper.js.
Node.js https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect/blob/master/requestUtil.js
, ADAL.js oauth2 id_token. , tenantId AAD application clientId, . ADAL.js access_token html5 sesstionStorage. http://www.cloudidentity.com/blog/2015/02/19/introducing-adal-js-v1/ http://www.cloudidentity.com/blog/2014/10/28/adal-javascript-and-angularjs-deep-dive/ .
ADAL.js JWT - , https://github.com/matvelloso/AADNodeJWT.
, , MEAN 2 Azure Web Apps. , angular , - Expressjs Node.js -.
-- Azure Active Directory -Apis. . https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-active-directory-authentication/.
- adal.js adal-angular.js angular . https://github.com/matvelloso/AADNodeJWT.
adal.js
adal-angular.js
, adal.js idtoken html5 sesstionstorage, -, AAD:
idtoken
html5 sesstionstorage
var token = sessionStorage.getItem('adal.idtoken'); $http.defaults.headers.common.Authorization= 'Bearer '+token; $http.get('https://<your_backend_apis>').then(function (data){ console.log(data); })
To authorize a Node.js server with Azure AD, you can use the adal-node library in Node.js.
The following example will demonstrate Node.js authentication with Azure AD, step by step:https://code.msdn.microsoft.com/How-to-authorize-Nodejs-fdc580ed