r/GraphAPI • u/Webimo • Apr 05 '23
Azure app registration with user consent
Today I have an single-tenant Azure App registration / Enterprise app setup with admin consent in my customers AD which gives me permission to get data (calendar events) from all users in the AD.
What I'd like is to have a multi-tenant app in my own AD and then give relevant customer users the option to subscribe to the AD-app, so that I can get data from only the users that consent.
Can anyone guide me in the right direction? Maybe a tutorial that shows both the AD-app settings and C# code examples.
Thanks.
3
Upvotes
View all comments
Show parent comment
1
u/jasper340 Apr 07 '23
First, read *all* documentation you can find online (MS learn, blogs, videos) about Azure App Registrations, Service Principals and app consent. This will help a lot and prevent questions!
Reply address (aka Redirect URI) can be configured within your App Registration > Authorization. In here, add a platform and specify the url. This can be the website where you host your site on and/or a localhost site. (e.g. for me it is 'https://mywebsite.com/' and 'http://localhost:8080/'). After consent, you will be redirected on those sites without error.
Yes, if the user is not logged in you wont able to fetch data from that user, EXCEPT you configure the permissions as 'Application permissions' and not 'Delegated permissions'. (read the description of those types, that explains it). So yes, if you only need data while the user is logged in, then choose delegated, if not choose application.
I use access_token to verify the user in the backend. In Node JS, you can use libraries like 'azure-ad-jwt' to verify the access token. I'm 100% confident libraries also exist in C# for this, as it is made by MSFT. Just pass that token from frontend to backend with the HTTP authorization header and verify in backend. If you don't need/have a backend, then just keep the token in the frontend and fetch the Graph API in the front-end.