I'm trying to do a node.js Application with a frontend (http://localhost:8080) and a API backend (http://localhost:5000). I would like to be authenticate by Azure AD in both cases.
It is my first application like that, so I don't know exactly how to handle it.
What I would like to do is :
- Login with Microsoft account on the frontend;
- When the user is logged, when getting a route (i.e. http://localhost:8080/list), call the backend API (http://localhost:5000/api/list) to retrieve information 'list' and render it (depending on the user access rights).
I was thinking using 'passport-azure-ad' but I don't know what strategy to do ? OIDCStrategy or BearerStrategy ?
I'am able to easily doing the frontend login with OIDCStrategy, but I don't have a 'Bearer', so I don't understand how I can use the same "login" for calling the backend API ? And with BearerStrategy, I have tried to get a Bearer by getting 'https://login.microsoftonline.com/'+MyTenantId+'/oauth2/v2.0/authorize?response_type=code&client_id='+MyClientId+'&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&scope=openid' but every time when I test it on jwt.io it return as an invalid bearer ( 'Invalid Signature') and I cannot use that bearer in my backend server.
I'm a bit confused how to do ? And I need help.
Thanks
As this document shows, you could make HTTP calls to get the access token. And you could try it with Postman.
Using on-behalf-of flow in node.js:
You could extract the access token and use it against a resource in a bearer request.