I have a WCF service hosted by Azure and secured by Azure AD. when I use the web to access the service I am prompted with the Azure login,after a successful login,I reach the data. I am trying to access the data form Winforms, I reach the OAuth2 login screen, I successfully login and get the token. I add the token to the context headers, but still receive this message:
InnerException = "You do not have permission to view this directory or page."
any help on how to access WCF secured with Azure AD, from Winforms ?
There could be multiple reasons for this error and it's hard to guess.
But here are few things to check.
Your client application (Winform) is registered with Azure AD and has
permission to access your web app. Make sure desktop/mobile apps have
to be registered wtih Azure AD as native app.
Your Audience is set correctly in Azure AD . I have seen many people
struggle if they don't have it set properly.
If your WCF is hosted in app services then turn on the real time logging. Go to app services and turn on the "Diagnostic logs".Under "Diagnostic logs" set the "application log" to verbose. After this go to "Log Stream" in app service to view the real time app logging. Now if you hit your web app with your client you should be able to see the why are you getting 401 unauthorized.
Hope that helps !