active-directory-javascript-nodejs-webapi-v2 | small Node.js Web API | Azure library
kandi X-RAY | active-directory-javascript-nodejs-webapi-v2 Summary
kandi X-RAY | active-directory-javascript-nodejs-webapi-v2 Summary
This sample demonstrates how to protect a Node.js Web API with the Microsoft identity platform and Azure Active Directory (Azure AD) using the passport-azure-ad library. You will need a client application for calling the web API. For a web API sample that is coupled with a client app, see: JavaScript Single-page application & Node.js web API Tutorial.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of active-directory-javascript-nodejs-webapi-v2
active-directory-javascript-nodejs-webapi-v2 Key Features
active-directory-javascript-nodejs-webapi-v2 Examples and Code Snippets
Community Discussions
Trending Discussions on active-directory-javascript-nodejs-webapi-v2
QUESTION
I am creating a SPA using React and Express. I am trying to include authentication using MSAL.js and have looked at Microsoft's tutorials for SPA. I've been able to implement this with React using @msal-react. While this does perform authentication, it does not protect the REST API from access by unauthenticated users.
I found the Active Directory Javascript Nodejs Web API that seems to provide a means for protecting the REST API using Passport and the Bearer strategy, but the links showing how to couple this with the client-side seem to be broken.
I'm not sure how to connect the authentication that is occurring on the client side with REST API. As I understand it, the authentication token has to be passed, but I am not sure how to pass that.
The server-side sample code has:
...ANSWER
Answered 2021-Jun-02 at 16:41When calling your protected REST API, you need to present an access token obtained by the client application (on behalf of the signed-in user). So the ID token won't do here -it's only meant for your client application as a proof of successful user authentication. (ideally, your client and service apps should be separate, each represented by an Azure AD app registration).
After authentication, you need to obtain an access token, by using one of the acquireToken*
methods. You pass a token request object to that method. Here you need to specify what resources and permissions you are requesting an access token for. The access token that would work with calling your REST API shouldn't/won't work with other APIs.
The tutorial article you linked points to a sample using implicit flow. I would recommend using the more secure auth code flow.
This tutorial should cover your need. Check this section in particular.
p.s. for a React client app, see this.
QUESTION
In the example the following piece of code is used:
...ANSWER
Answered 2020-Jul-27 at 10:04You can add types to each of the parameters.
new BearerStrategy(config, (token: ITokenPayload, done: CallableFunction) => ...
QUESTION
First I'm describing how I setup my applications then I will describe how I'm using the APIs.
Setup- In my Azure Active Directory, I have two applications registered: UI and Backend
- UI has the client ID clientId1 and backend has client ID clientId2 (it's a GUID, but for simplicity)
- Both are under the same tenant tentant1 (single tenant)
- Backend has an exposed API with scope "api://clientId2/access_as_user" and authorized client "clientId1" with the scope just mentioned selected
- I'm using
passport
andpassport-azure-ad
(I pretty much copied https://github.com/Azure-Samples/active-directory-javascript-nodejs-webapi-v2). My config:
...
ANSWER
Answered 2020-Apr-11 at 22:59Turns out their code in the repository is not using proper configuration to verify the scope access...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install active-directory-javascript-nodejs-webapi-v2
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page